Skip to content
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

Closed
kabcasa opened this issue Mar 6, 2022 · 25 comments
Closed

RuntimeError: Sending request failed #101

kabcasa opened this issue Mar 6, 2022 · 25 comments

Comments

@kabcasa
Copy link

kabcasa commented Mar 6, 2022

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

<

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


try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

print("ESP32 SPI webclient test")

TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
JSON_URL = "http://calendar2.priyom.org/events?timeMin=2022-03-04T00:00:00.000Z&amp;timeMax=2022-03-05T00:00:00.000Z"

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)

requests.set_socket(socket, esp)

if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
    print("ESP32 found and in idle mode")
print("Firmware vers.", esp.firmware_version)
print("MAC addr:", [hex(i) for i in esp.MAC_address])

for ap in esp.scan_networks():
    print("\t%s\t\tRSSI: %d" % (str(ap["ssid"], "utf-8"), ap["rssi"]))

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("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
print("My IP address is", esp.pretty_ip(esp.ip_address))
print(
    "IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com"))
)
print("Ping google.com: %d ms" % esp.ping("google.com"))

print("Fetching text from", TEXT_URL)
r = requests.get(TEXT_URL)
print("-" * 40)
print(r.text)
print("-" * 40)
r.close()

print()
print("Fetching json from", JSON_URL)
r = requests.get(JSON_URL)
print("-" * 40)
print(r.json())
print("-" * 40)
r.close()

print("Done!")

test result :

<

ESP32 SPI webclient test
ESP32 found and in idle mode
Firmware vers. bytearray(b'1.2.2\x00')
MAC addr: ['0xcc', '0x5f', '0x43', '0xc2', '0x9d', '0x1c']
Looney2 RSSI: -35
Looney5G RSSI: -48
Looney2 RSSI: -54
Looney2 RSSI: -55
Looney2 RSSI: -56
EasyLighting_23D26FB2 RSSI: -62
Looney2 RSSI: -67
Looney2 RSSI: -73
Looney2 RSSI: -77
Looney2 RSSI: -83
Connecting to AP...
Connected to Looney5G RSSI: -47
My IP address is ..................................
IP lookup adafruit.com: ..................
Ping google.com: 130 ms
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
----------------------------------------
This is a test of Adafruit WiFi!
If you can read this, its working 
----------------------------------------

Fetching json from http://calendar2.priyom.org/events?timeMin=2022-03-04T00:00:00.000Z&amp;timeMax=2022-03-05T00:00:00.000Z
Traceback (most recent call last):
File "code.py", line 68, in <module>
File "adafruit_requests.py", line 864, in get
File "adafruit_requests.py", line 758, in request
File "adafruit_requests.py", line 710, in request
File "adafruit_requests.py", line 563, in _get_socket
RuntimeError: Sending request failed

Code done running.
>

Originally posted by @kabcasa in #62 (comment)

@anecdata
Copy link
Member

anecdata commented Mar 6, 2022

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:
https://learn.adafruit.com/upgrading-esp32-firmware

@kabcasa
Copy link
Author

kabcasa commented Mar 6, 2022

@anecdata
Thank you for your comment
why this https url is working
URL = "https://api.openweathermap.org/data/2.5/onecall?exclude=minutely,hourly,alerts"

Anyway i will update the firmware

@anecdata
Copy link
Member

anecdata commented Mar 6, 2022

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.

@kabcasa
Copy link
Author

kabcasa commented Mar 6, 2022

i have updated the frimware but still can't get it
`<

ESP32 SPI webclient test
ESP32 found and in idle mode
Firmware vers. bytearray(b'1.7.4\x00')
MAC addr: ['0xcc', '0x5f', '0x43', '0xc2', '0x9d', '0x1c']
Looney2 RSSI: -53
Looney2 RSSI: -54
Looney5G RSSI: -59
Looney2 RSSI: -68
EasyLighting_23D26FB2 RSSI: -72
CenturyLink9993 RSSI: -87
SoccerBall RSSI: -89
Looney2 RSSI: -93
Connecting to AP...
could not connect to AP, retrying: ('Failed to connect to ssid', b'Looney5G')
Connected to Looney5G RSSI: -54
My IP address is ......
IP lookup adafruit.com: ..........
Ping google.com: 110 ms
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
----------------------------------------
This is a test of Adafruit WiFi!
If you can read this, its working :)
----------------------------------------

Fetching json from https://calendar2.priyom.org/events?timeMin=2022-03-04T00:00:00.000Z&amp;timeMax=2022-03-05T00:00:00.000Z
Traceback (most recent call last):
File "code.py", line 68, in <module>
File "adafruit_requests.py", line 864, in get
File "adafruit_requests.py", line 710, in request
File "adafruit_requests.py", line 563, in _get_socket
RuntimeError: Sending request failed

Code done running.>`

@anecdata
Copy link
Member

anecdata commented Mar 6, 2022

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 since this URL also does not work on ESP32-S2, even with the latest NINA submodule update (done to get the updated certificates).

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.

@anecdata
Copy link
Member

anecdata commented Mar 6, 2022

It does look like a certificate issue. On ESP32-S2, if I manually supply a certificate (using context.load_verify_locations(cadata=CA_STRING)), the request is successful.

@kabcasa
Copy link
Author

kabcasa commented Mar 6, 2022

It does look like a certificate issue. On ESP32-S2, if I manually supply a certificate (using context.load_verify_locations(cadata=CA_STRING)), the request is successful.

Please could you share how to code this

@anecdata
Copy link
Member

anecdata commented Mar 6, 2022

That was on an ESP32-S2, that code won't work on MatrixPortal. I did try to supply a custom certificate in ESP32SPI using esp.set_certificate(CA_STRING) (e.g., MatrixPortal, PyPortal), but it's apparently too long:
AssertionError: .PEM must be less than 1300 bytes. Though I may be supplying the wrong format; I used the same certificate string as on ESP32-S2.

@anecdata
Copy link
Member

anecdata commented Mar 6, 2022

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" \
    "cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4" \
    "WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu" \
    "ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY" \
    "MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc" \
    "h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+" \
    "0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U" \
    "A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW" \
    "T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH" \
    "B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC" \
    "B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJBdiB3QW0KtZB6awBdpUKD9jf1b0SHzUv" \
    "KBds0pjBqAlkd25HN7rOrFleaJ1/ctaJxQZBKT5ZPt0m9STJEadao0xAH0ahmbWn" \
    "OlFuhjuefXKnEgV4We0+UXgVCwOPjdAvBbI+e0ocS3MFEvzG6uBQE3xDk3SzynTn" \
    "jh8BCNAw1FtxNrQHusEwMFxIt4I7mKZ9YIqioymCzLq9gwQbooMDQaHWBfEbwrbw" \
    "qHyGO0aoSCqI3Haadr8faqU9GY/rOPNk3sgrDQoo//fb4hVC1CLQJ13hef4Y53CI" \
    "rU7m2Ys6xt0nUW7/vGT1M0NPAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNV" \
    "HRMBAf8EBTADAQH/MB0GA1UdDgQWBBR5tFnme7bl5AFzgAiIyBpY9umbbjANBgkq" \
    "hkiG9w0BAQsFAAOCAgEAVR9YqbyyqFDQDLHYGmkgJykIrGF1XIpu+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:

code.py output:
200 bytearray(b'OK') {'server': 'Microsoft-IIS/8.5', 'x-powered-by': 'ASP.NET', 'content-type': 'application/json', 'date': 'Sun, 06 Mar 2022 19:51:29 GMT', 'x-powered-by-plesk': 'PleskWin', 'content-length': '9573', 'access-control-allow-origin': 'https://priyom.org'}
{'items': [{'start': {'dateTime': '2022-03-04T00:00:00.000Z'}, 'summary': 'V13 15890kHz USB/AM [Target: East Asia]'}, {'start': {'dateTime': '2022-03-04T00:00:00.000Z'}, 'summary': 'F01 22936kHz RTTY [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T00:10:00.000Z'}, 'summary': 'M12 16284kHz CW [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T00:10:00.000Z'}, 'summary': 'F01 20331kHz RTTY [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T00:20:00.000Z'}, 'summary': 'F01 17471kHz RTTY [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T00:30:00.000Z'}, 'summary': 'M12 5863kHz CW'}, {'start': {'dateTime': '2022-03-04T00:30:00.000Z'}, 'summary': 'M12 15984kHz CW [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T00:50:00.000Z'}, 'summary': 'M12 7463kHz CW'}, {'start': {'dateTime': '2022-03-04T00:50:00.000Z'}, 'summary': 'M12 14784kHz CW (In case of traffic) [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T01:00:00.000Z'}, 'summary': 'V13 13974kHz, 15890kHz, 18040kHz USB/AM [Target: East Asia]'}, {'start': {'dateTime': '2022-03-04T01:00:00.000Z'}, 'summary': 'F01 17532kHz RTTY [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T01:10:00.000Z'}, 'summary': 'M12 8163kHz CW (In case of traffic)'}, {'start': {'dateTime': '2022-03-04T01:10:00.000Z'}, 'summary': 'F01 16351kHz RTTY [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T01:20:00.000Z'}, 'summary': 'F01 14428kHz RTTY [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T02:00:00.000Z'}, 'summary': 'F06 13370kHz RTTY [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T02:10:00.000Z'}, 'summary': 'F06 11538kHz RTTY [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T02:20:00.000Z'}, 'summary': 'F06 10614kHz RTTY [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T03:00:00.000Z'}, 'summary': 'V13 11430kHz USB/AM [Target: East Asia]'}, {'start': {'dateTime': '2022-03-04T03:00:00.000Z'}, 'summary': 'F06 11563kHz RTTY [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T03:00:00.000Z'}, 'summary': 'E06 15726kHz USB/AM [Target: East Asia]'}, {'start': {'dateTime': '2022-03-04T03:10:00.000Z'}, 'summary': 'F06 10216kHz RTTY [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T03:20:00.000Z'}, 'summary': 'F06 9417kHz RTTY [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T04:00:00.000Z'}, 'summary': 'S06 11616kHz USB/AM [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T04:00:00.000Z'}, 'summary': 'E06 13384kHz USB/AM [Target: East Asia]'}, {'start': {'dateTime': '2022-03-04T04:20:00.000Z'}, 'summary': 'S06 9322kHz USB/AM [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T05:00:00.000Z'}, 'summary': 'F06a 6895kHz RTTY'}, {'start': {'dateTime': '2022-03-04T05:00:00.000Z'}, 'summary': 'HM01 10860kHz AM'}, {'start': {'dateTime': '2022-03-04T05:00:00.000Z'}, 'summary': 'M14 12211kHz CW [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T05:15:00.000Z'}, 'summary': 'F06a 5813kHz RTTY'}, {'start': {'dateTime': '2022-03-04T05:20:00.000Z'}, 'summary': 'M14 10243kHz CW [Target: Pacific]'}, {'start': {'dateTime': '2022-03-04T05:30:00.000Z'}, 'summary': 'F06a 4799kHz RTTY'}, {'start': {'dateTime': '2022-03-04T05:30:00.000Z'}, 'summary': 'P03k 9200kHz USB'}, {'start': {'dateTime': '2022-03-04T05:40:00.000Z'}, 'summary': 'F03 Search (Tentative)'}, {'start': {'dateTime': '2022-03-04T05:50:00.000Z'}, 'summary': 'F03 Search (Tentative)'}, {'start': {'dateTime': '2022-03-04T06:00:00.000Z'}, 'summary': 'E11 8680kHz USB'}, {'start': {'dateTime': '2022-03-04T06:00:00.000Z'}, 'summary': 'HM01 10345kHz AM'}, {'start': {'dateTime': '2022-03-04T06:00:00.000Z'}, 'summary': 'E06 16230kHz USB/AM'}, {'start': {'dateTime': '2022-03-04T06:25:00.000Z'}, 'summary': 'F03 Search (Tentative)'}, {'start': {'dateTime': '2022-03-04T07:00:00.000Z'}, 'summary': 'E11 8180kHz USB'}, {'start': {'dateTime': '2022-03-04T07:00:00.000Z'}, 'summary': 'HM01 9330kHz AM'}, {'start': {'dateTime': '2022-03-04T07:00:00.000Z'}, 'summary': 'F06 10671kHz RTTY'}, {'start': {'dateTime': '2022-03-04T07:00:00.000Z'}, 'summary': 'E07 14942kHz USB'}, {'start': {'dateTime': '2022-03-04T07:00:00.000Z'}, 'summary': 'E06 19325kHz USB/AM'}, {'start': {'dateTime': '2022-03-04T07:10:00.000Z'}, 'summary': 'F06 8093kHz RTTY'}, {'start': {'dateTime': '2022-03-04T07:15:00.000Z'}, 'summary': 'E11 9963kHz USB'}, {'start': {'dateTime': '2022-03-04T07:20:00.000Z'}, 'summary': 'F06 6879kHz RTTY'}, {'start': {'dateTime': '2022-03-04T07:20:00.000Z'}, 'summary': 'E07 16142kHz USB'}, {'start': {'dateTime': '2022-03-04T07:40:00.000Z'}, 'summary': 'E07 18042kHz USB (In case of traffic)'}, {'start': {'dateTime': '2022-03-04T07:45:00.000Z'}, 'summary': 'E11 17410kHz USB'}, {'start': {'dateTime': '2022-03-04T08:00:00.000Z'}, 'summary': 'F03j 5409kHz USB'}, {'start': {'dateTime': '2022-03-04T08:00:00.000Z'}, 'summary': 'HM01 9065kHz AM'}, {'start': {'dateTime': '2022-03-04T08:10:00.000Z'}, 'summary': 'F03l 12385kHz USB'}, {'start': {'dateTime': '2022-03-04T08:20:00.000Z'}, 'summary': 'E11 5941kHz USB'}, {'start': {'dateTime': '2022-03-04T08:30:00.000Z'}, 'summary': 'S06s 12140kHz USB/AM (Canceled due to invasion; please report any activity)'}, {'start': {'dateTime': '2022-03-04T08:30:00.000Z'}, 'summary': 'E11 15905kHz USB'}, {'start': {'dateTime': '2022-03-04T08:30:00.000Z'}, 'summary': 'S06 19415kHz USB/AM [Target: East Asia]'}, {'start': {'dateTime': '2022-03-04T08:40:00.000Z'}, 'summary': 'S06s 13515kHz USB/AM (Canceled due to invasion; please report any activity)'}, {'start': {'dateTime': '2022-03-04T08:50:00.000Z'}, 'summary': 'F03j 9339kHz USB'}, {'start': {'dateTime': '2022-03-04T09:00:00.000Z'}, 'summary': 'S06s 5744kHz USB/AM (Canceled due to invasion; please report any activity)'}, {'start': {'dateTime': '2022-03-04T09:00:00.000Z'}, 'summary': 'HM01 9240kHz AM'}, {'start': {'dateTime': '2022-03-04T09:10:00.000Z'}, 'summary': 'S06s 6524kHz USB/AM (Canceled due to invasion; please report any activity)'}, {'start': {'dateTime': '2022-03-04T09:15:00.000Z'}, 'summary': 'S11a 6480kHz USB'}, {'start': {'dateTime': '2022-03-04T09:30:00.000Z'}, 'summary': 'F03l 6397kHz USB'}, {'start': {'dateTime': '2022-03-04T09:30:00.000Z'}, 'summary': 'S06 16268kHz USB/AM [Target: East Asia]'}, {'start': {'dateTime': '2022-03-04T09:45:00.000Z'}, 'summary': 'F03l 6480kHz USB'}, {'start': {'dateTime': '2022-03-04T10:00:00.000Z'}, 'summary': 'HM01 9155kHz AM'}, {'start': {'dateTime': '2022-03-04T10:00:00.000Z'}, 'summary': 'E11 9951kHz USB'}, {'start': {'dateTime': '2022-03-04T10:15:00.000Z'}, 'summary': 'F01 10861kHz RTTY'}, {'start': {'dateTime': '2022-03-04T10:25:00.000Z'}, 'summary': 'F01 8187kHz RTTY'}, {'start': {'dateTime': '2022-03-04T10:35:00.000Z'}, 'summary': 'F01 6939kHz RTTY'}, {'start': {'dateTime': '2022-03-04T11:00:00.000Z'}, 'summary': 'P03k 8180kHz USB'}, {'start': {'dateTime': '2022-03-04T11:00:00.000Z'}, 'summary': 'XPA2 14639kHz USB'}, {'start': {'dateTime': '2022-03-04T11:20:00.000Z'}, 'summary': 'XPA2 13539kHz USB'}, {'start': {'dateTime': '2022-03-04T11:40:00.000Z'}, 'summary': 'XPA2 12139kHz USB'}, {'start': {'dateTime': '2022-03-04T12:00:00.000Z'}, 'summary': 'V13 9276kHz, 13974kHz USB/AM [Target: East Asia]'}, {'start': {'dateTime': '2022-03-04T12:00:00.000Z'}, 'summary': 'XPA2 12139kHz USB'}, {'start': {'dateTime': '2022-03-04T12:20:00.000Z'}, 'summary': 'XPA2 13539kHz USB'}, {'start': {'dateTime': '2022-03-04T12:40:00.000Z'}, 'summary': 'XPA2 14639kHz USB'}, {'start': {'dateTime': '2022-03-04T13:00:00.000Z'}, 'summary': 'V13 7688kHz, 11430kHz USB/AM [Target: East Asia]'}, {'start': {'dateTime': '2022-03-04T13:10:00.000Z'}, 'summary': 'XPA 14451kHz USB'}, {'start': {'dateTime': '2022-03-04T13:30:00.000Z'}, 'summary': 'XPA 13451kHz USB'}, {'start': {'dateTime': '2022-03-04T13:30:00.000Z'}, 'summary': 'F03l 15915kHz USB'}, {'start': {'dateTime': '2022-03-04T13:45:00.000Z'}, 'summary': 'P03l 7984kHz USB'}, {'start': {'dateTime': '2022-03-04T13:50:00.000Z'}, 'summary': 'XPA 12151kHz USB'}, {'start': {'dateTime': '2022-03-04T15:00:00.000Z'}, 'summary': 'F03l 7984kHz USB'}, {'start': {'dateTime': '2022-03-04T15:15:00.000Z'}, 'summary': 'P03e 14972kHz USB'}, {'start': {'dateTime': '2022-03-04T16:00:00.000Z'}, 'summary': 'HM01 11435kHz AM [Target: North America]'}, {'start': {'dateTime': '2022-03-04T17:00:00.000Z'}, 'summary': 'HM01 11530kHz AM [Target: North America]'}, {'start': {'dateTime': '2022-03-04T17:15:00.000Z'}, 'summary': 'E11 6923kHz USB'}, {'start': {'dateTime': '2022-03-04T18:00:00.000Z'}, 'summary': 'HM01 11635kHz AM [Target: North America]'}, {'start': {'dateTime': '2022-03-04T18:15:00.000Z'}, 'summary': 'E11 11116kHz USB'}, {'start': {'dateTime': '2022-03-04T19:10:00.000Z'}, 'summary': 'E11 8530kHz USB'}, {'start': {'dateTime': '2022-03-04T20:00:00.000Z'}, 'summary': 'S06 9268kHz USB/AM'}, {'start': {'dateTime': '2022-03-04T20:00:00.000Z'}, 'summary': 'M12 10238kHz CW'}, {'start': {'dateTime': '2022-03-04T20:20:00.000Z'}, 'summary': 'M12 9138kHz CW'}, {'start': {'dateTime': '2022-03-04T20:40:00.000Z'}, 'summary': 'M12 Search (In case of traffic) [Last used: 5774kHz]'}, {'start': {'dateTime': '2022-03-04T21:00:00.000Z'}, 'summary': 'S06 6775kHz USB/AM'}, {'start': {'dateTime': '2022-03-04T21:00:00.000Z'}, 'summary': 'HM01 11635kHz AM [Target: North America]'}, {'start': {'dateTime': '2022-03-04T22:00:00.000Z'}, 'summary': 'M12 8126kHz CW'}, {'start': {'dateTime': '2022-03-04T22:00:00.000Z'}, 'summary': 'HM01 10715kHz AM [Target: North America]'}, {'start': {'dateTime': '2022-03-04T22:20:00.000Z'}, 'summary': 'M12 7526kHz CW'}, {'start': {'dateTime': '2022-03-04T22:30:00.000Z'}, 'summary': 'F01 20700kHz RTTY [Target: North America]'}, {'start': {'dateTime': '2022-03-04T22:40:00.000Z'}, 'summary': 'M12 6826kHz CW (In case of traffic)'}, {'start': {'dateTime': '2022-03-04T22:40:00.000Z'}, 'summary': 'F01 18726kHz RTTY [Target: North America]'}, {'start': {'dateTime': '2022-03-04T23:30:00.000Z'}, 'summary': 'F01 20700kHz RTTY [Target: North America]'}, {'start': {'dateTime': '2022-03-04T23:40:00.000Z'}, 'summary': 'F01 18726kHz RTTY [Target: North America]'}]}

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.

@anecdata
Copy link
Member

anecdata commented Mar 6, 2022

The 1300-character limit (AssertionError: .PEM must be less than 1300 bytes.) apparently arises in the NINA firmware (or perhaps deeper, in the Espressif Arduino code that NINA is built upon):
https://github.com/adafruit/nina-fw/blob/d73fe315cc7f9148a0918490d3b75430c8444bf7/main/CommandHandler.cpp#L34
I've filed an issue there:
adafruit/nina-fw#42

@kabcasa
Copy link
Author

kabcasa commented Mar 6, 2022

@anecdata
Thanks a lot

@kabcasa
Copy link
Author

kabcasa commented Mar 7, 2022

I'm not sure if that can help
https://forums.adafruit.com/viewtopic.php?f=60&t=170089&p=831515&hilit=esp32spi+certificate#p831515

I'm sorry I'm new to certificates . From where did you get the certificate that you use in your code.

@anecdata
Copy link
Member

anecdata commented Mar 7, 2022

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:
https://github.com/espressif/esp-idf/blob/master/examples/protocols/https_request/main/server_root_cert.pem

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 esp.set_certificate() function looked like it should do what we needed (like its ESP32-S2 counterpart), but it had the 1300 character limit.

@anecdata
Copy link
Member

anecdata commented Mar 7, 2022

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.

@kabcasa
Copy link
Author

kabcasa commented Mar 7, 2022

Thanks again.
But it's working with ESP32-S2 and not for ESP32-SP1 that means we still have the issue even after the NINA will be updated if the limit of 1.3k is not resolved .
We have tested after updated to NINA 1.7.4

@anecdata
Copy link
Member

anecdata commented Mar 7, 2022

The 1300-byte limit is only for manually-supplied certificates using esp.set_certificate(). Once the NINA firmware is updated with the new certificate permanently embedded in the firmware, this URL should work.

@kabcasa
Copy link
Author

kabcasa commented Mar 7, 2022

The 1300-byte limit is only for manually-supplied certificates using esp.set_certificate(). Once the NINA firmware is updated with the new certificate permanently embedded in the firmware, this URL should work.

temporarily is it possible to set the requests verify to False as for python
requests.get('https://example.com', verify=False)

@anecdata
Copy link
Member

anecdata commented Mar 7, 2022

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.

@anecdata
Copy link
Member

anecdata commented Mar 8, 2022

@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:
https://github.com/adafruit/nina-fw#readme

@kabcasa
Copy link
Author

kabcasa commented Mar 8, 2022

@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: https://github.com/adafruit/nina-fw#readme

i have try but get error when running : make firmware

App "nina-fw" version: 1.7.4-4-gd73fe31
/home/pi/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc: 1: /home/pi/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc: Syntax error: "(" unexpected
expr: syntax error: unexpected argument ‘5.2.0’
/home/pi/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc: 1: /home/pi/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc: Syntax error: "(" unexpected
expr: syntax error: unexpected argument ‘5.2.0’
/bin/sh: 1: xtensa-esp32-elf-gcc: Exec format error
/bin/sh: 1: xtensa-esp32-elf-gcc: Exec format error
WARNING: Failed to find Xtensa toolchain, may need to alter PATH or set one in the configuration menu
/home/pi/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc: 1: /home/pi/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc: Syntax error: "(" unexpected
expr: syntax error: unexpected argument ‘5.2.0’
CC build/bootloader/bootloader_support/src/bootloader_flash.o
/home/pi/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc: 1: /home/pi/esp/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc: Syntax error: "(" unexpected
make[2]: *** [/home/pi/esp/esp-idf/make/component_wrapper.mk:290: src/bootloader_flash.o] Error 2
make[1]: *** [/home/pi/esp/esp-idf/make/project.mk:552: component-bootloader_support-build] Error 2
make: *** [/home/pi/esp/esp-idf/components/bootloader/Makefile.projbuild:41: /home/pi/adafruit/nina-fw/build/bootloader/bootloader.bin] Error 2
```
`
Did you already try it in your side 

@anecdata
Copy link
Member

anecdata commented Mar 8, 2022

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.

@kabcasa
Copy link
Author

kabcasa commented Mar 13, 2022

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
Hi i could finally update the firmware in Windows.
That could resolve the url request issue.

@kabcasa kabcasa closed this as completed Mar 13, 2022
@kabcasa
Copy link
Author

kabcasa commented Mar 13, 2022

resolved after updated nina-fw firmaware

@crhuber
Copy link

crhuber commented Sep 20, 2023

Still an issue for me on Circuit Python 8.2.6 and nina-fw 1.7.5 and Pyportal
The cert in question is a cloudflare cert

@dhalbert
Copy link
Contributor

Still an issue for me on Circuit Python 8.2.6 and nina-fw 1.7.5 and Pyportal The cert in question is a cloudflare cert

Being addressed in adafruit/nina-fw#55 and adafruit/nina-fw#57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants