adafruit / Adafruit_CircuitPython_Requests

Requests-like interface for web interfacing
MIT License
51 stars 36 forks source link

ESP32SPI HTTP (non-secure) URLs get OutOfRetries: Repeated socket failures #79

Closed anecdata closed 2 years ago

anecdata commented 2 years ago

Consistently repeatable, not intermittent: https://httpbin.org/get and other HTTPS URLs work fine http://httpbin.org/get does not work (it does work with browser and curl) http://wifitest.adafruit.com/testwifi/index.html does not work (it does work with browser and curl)

Configuration: Adafruit CircuitPython 7.0.0 on 2021-09-20; Adafruit PyPortal with samd51j20 adafruit-circuitpython-bundle-7.x-mpy-20210925

Modified simpletest:

import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests

from secrets import secrets

esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)

print("Connecting to AP...")
while not esp.is_connected:
    try:
        esp.connect_AP(secrets["ssid"], secrets["password"])
    except RuntimeError as e:
        print("could not connect to AP, retrying: ", e)
        continue
print("RSSI:", esp.rssi)

socket.set_interface(esp)
requests.set_socket(socket, esp)

URLS = [
        # "https://httpbin.org/get",  # OK
        "http://httpbin.org/get"  # Not OK
       ]
for url in URLS:
    print(url, end=" ")
    r = requests.get(url)
    print(r.status_code, r.reason)
    r.close()

Results:

code.py output:
Connecting to AP...
RSSI: -60
http://httpbin.org/get Traceback (most recent call last):
  File "code.py", line 35, in <module>
  File "adafruit_requests.py", line 698, in get
  File "adafruit_requests.py", line 580, in request
OutOfRetries: Repeated socket failures

Same behavior with NINA 1.6.0 and 1.7.4

anecdata commented 2 years ago

Closing. Turns out this is an issue with one of my WAN providers.