-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeError: Sending request failed #101
Comments
The HTTP site redirects to HTTPS, and it seems the library doesn't handle redirects with a protocol change. Not loading the HTTPS site directly could be a certificate issue. Looks like the NINA firmware version on the MatrixPortal is 1.2.2. There have been certificate updates since then. My PyPortal with 1.7.4 loads the HTTPS site. There's an update learn guide here: |
@anecdata Anyway i will update the firmware |
There are certificates in the v1.2.2 firmware that handle most HTTPS sites, but there is occasionally one that does not work and it often turns out to be handled by a certificate in the newer bundle in the upgraded firmware. |
i have updated the frimware but still can't get it
|
You're right. I'm not sure what I was seeing yesterday, but I get the same exception on PyPortal with 1.7.4 today. Also, running ESP32SPI with debug=1, it's apparent that redirections from HTTP to HTTPS are handled properly; Requests gets a new socket with the updated port / protocol. I think it's still possible it's a certificate issue EDIT: turns out I had flashed the wrong version, latest CircuitPython (within the past 6 days) have the new cert included and work without manually supplying the cert. |
It does look like a certificate issue. On ESP32-S2, if I manually supply a certificate (using |
Please could you share how to code this |
That was on an ESP32-S2, that code won't work on MatrixPortal. I did try to supply a custom certificate in ESP32SPI using |
ESP32-S2 code (won't work on ESP32SPI / Airlift devices like MatrixPortal): import wifi
import socketpool
import ssl
import adafruit_requests
from secrets import secrets
URL = "https://calendar2.priyom.org/events?timeMin=2022-03-04T00:00:00.000Z&timeMax=2022-03-05T00:00:00.000Z"
CA_STRING = "-----BEGIN CERTIFICATE-----\n" \
"MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw" \
"TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh" \
"cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTE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HYGmkgJykIrGF1XIpu+ILlaS/V9lZL" \
"ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ" \
"3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK" \
"NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5" \
"ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur" \
"TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC" \
"jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc" \
"oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq" \
"4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA" \
"mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d" \
"emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n" \
"-----END CERTIFICATE-----"
wifi.radio.connect(secrets['ssid'], secrets['password'])
pool = socketpool.SocketPool(wifi.radio)
context = ssl.create_default_context()
context.load_verify_locations(cadata=CA_STRING)
requests = adafruit_requests.Session(pool, context)
with requests.get(URL) as response:
print(response.status_code, response.reason, response.headers)
print(response.json()) gives:
This URL does not work without a manually-supplied certificate ...EDIT... on CircuitPython 7.2.0, but it does work on very recent versions with the NINA submodule updated. |
The 1300-character limit ( |
@anecdata |
I'm not sure if that can help I'm sorry I'm new to certificates . From where did you get the certificate that you use in your code. |
The certificate I used is somewhat random, it just worked in a prior similar case so I tried it here. It's from an Espressif example: Thanks for the forum link. New certs could certainly be built into new NINA firmware. I don't really know much about certificates either, but I thought the |
Looks like that cert has been added to the NINA repo, but it has not yet been re-built and re-released. You can watch the NINA repo for a new version, which (I hope) should fix your issue. Silly mistake above... I thought I had updated my ESP32-S2 to the version (anything since 6 days ago) including the new cert, but flashed the wrong version (I've edited comments above). But now having done so, it works without the manual certificate on ESP32-S2, which is a good sign for when a new NINA version gets released. |
Thanks again. |
The 1300-byte limit is only for manually-supplied certificates using |
temporarily is it possible to set the requests verify to False as for python |
I don't see it in the ESP32SPI API ESP32-S2 has this: pool = socketpool.SocketPool(wifi.radio)
context = ssl.create_default_context()
context.check_hostname = False
requests = adafruit_requests.Session(pool, context) but in this issue (and a prior certificate issue) it was not enough to allow successful loading of the URL. |
@kabcasa If you're in a hurry for this, you can build the NINA firmware. It's a little involved, but it can be done: |
i have try but get error when running : make firmware
|
It's been a couple of years since I built NINA. I'm not sure how to interpret those errors, this may need someone more expert to weigh in or do the build. You could file an issue in the NINA repository indicating that a needed certificate has been merged but not built or released. That might make the need more visible. |
@anecdata |
resolved after updated nina-fw firmaware |
Still an issue for me on Circuit Python 8.2.6 and nina-fw 1.7.5 and Pyportal |
Being addressed in adafruit/nina-fw#55 and adafruit/nina-fw#57 |
Get error message when running following code in Matrix Portal M4
RuntimeError: Sending request failed
and cannot retrieve the json response from this url :
"https://calendar2.priyom.org/events?timeMin=2022-03-04T00:00:00.000Z&timeMax=2022-03-05T00:00:00.000Z"
The execution succeeds with the error:
File "adafruit_requests.py", line 563, in _get_socket
RuntimeError: Sending request failed
I had no problem getting the response with a requests on a python3 script.
Currently my internet connection is a little weak and I suspect that this is the cause.
To confirm I would have liked someone with a better connection to do the test
<
test result :
<
Originally posted by @kabcasa in #62 (comment)
The text was updated successfully, but these errors were encountered: