adafruit / Adafruit_CircuitPython_Requests

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

"RuntimeError: Sending request failed" for https URL #114

Open izuk opened 1 year ago

izuk commented 1 year ago

Getting the above error:

Adafruit CircuitPython 7.3.2 on 2022-07-20; Adafruit QT Py ESP32S2 with ESP32S2
[...]

>>> adafruit_requests.__version__
'1.12.4'

>>> response = requests.get("https://www.flightstats.com")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "adafruit_requests.py", line 726, in get
  File "adafruit_requests.py", line 667, in request
  File "adafruit_requests.py", line 518, in _get_socket
RuntimeError: Sending request failed

I've seen this reported a few times, but I'm still not clear on which library, exactly, is failing and where to look for an update that fixes it.

Here's what curl -v reports for flightstats.com:

* Connected to www.flightstats.com (54.208.3.224) port 443 (#0)
* ALPN: offers h2
* ALPN: offers http/1.1
} [5 bytes data]
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.3 (IN), TLS handshake, Server hello (2):
{ [64 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [3388 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [300 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [37 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=flightstats.com; O=LNRS Data Services Ltd; L=Sutton; ST=Surrey; C=GB
*  start date: Jun 14 07:10:36 2022 GMT
*  expire date: Jun 14 07:09:36 2023 GMT
*  subjectAltName: host "www.flightstats.com" matched cert's "www.flightstats.com"
*  issuer: C=US; ST=Illinois; L=Chicago; O=Trustwave Holdings, Inc.; CN=Trustwave Organization Validation SHA256 CA, Level 1; emailAddress=ca@trustwave.com
*  SSL certificate verify ok.
* Using HTTP2, server supports multiplexing
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
} [5 bytes data]

Is the problem the size of the certificate? The encoding? I wish I knew where to look.

tannewt commented 1 year ago

I'd suggest starting with the requests library. There are a number of excepts here that may be catching the more relevant error: https://github.com/adafruit/Adafruit_CircuitPython_Requests/blob/main/adafruit_requests.py#L521-L541

anecdata commented 1 year ago

Added some print statements to Requests. It's failing here with OSError: Failed SSL handshake. I'm running 7.3.3, which has the updated certificates. It's possibly an issue with TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256.

anecdata commented 1 year ago

@izuk You may want to try the solution from: https://github.com/adafruit/circuitpython/issues/7429#event-8392828172