-
Notifications
You must be signed in to change notification settings - Fork 1.3k
SSL error with 8.2.2 or later when talking to github #8299
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
Comments
Removed adafruit gets and focused only on the Github connection. It's not connecting to that API url. Rest of the script seems to work fine. It's specifically the Github handshake attempt. |
Here's a slimmer version that will fail gracefully during testing. import os
import time
import ipaddress
import ssl
import wifi
import socketpool
import adafruit_requests
pool = socketpool.SocketPool(wifi.radio)
JSON_STARS_URL = "https://api.github.com/repos/adafruit/circuitpython"
# Connect to Wi-Fi
print("\n====== MatrixPortal S3 WebClient Test ======")
print("Connecting to WiFi...")
requests = adafruit_requests.Session(pool, ssl.create_default_context())
while not wifi.radio.ipv4_address:
try:
wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))
except ConnectionError as e:
print("Connection Error:", e)
print("Retrying in 10 seconds")
time.sleep(10)
print("Connected!\n")
while True:
try:
response = requests.get(JSON_STARS_URL).json()
stargazers_count = response['stargazers_count']
print(f"CircuitPython GitHub Stars: {stargazers_count}")
except (ValueError, RuntimeError, OSError) as e:
print("Failed to get data, retrying\n", e)
time.sleep(60)
continue
response = None
print("Done") With the OSError handler in the mix it spits out ====== MatrixPortal WebClient Test ======
Connecting to WiFi...
Connected!
Failed to get data, retrying
Sending request failed
Failed to get data, retrying
Sending request failed
Failed to get data, retrying
Sending request failed
Failed to get data, retrying
Sending request failed With The script will attempt to connect indefinitely so no sense waiting for it to connect. I have no idea why it isn't working with Github. Did something change with Github's API? It's not a key:value pair error, it's a handshake error, which out of my comfort zone to track down. |
Tried on an Adafruit ESP32-S2 Feather on 8.2.3 with the same result. Reverted the same S2 back to CP 8.2.0 and it works. Adafruit CircuitPython 8.2.0 on 2023-07-05; Adafruit Feather ESP32S2 with ESP32S2
Board ID:adafruit_feather_esp32s2 ====== Circuit Python Internet Simple Test ======
Connecting to WiFi...
Connected!
CircuitPython GitHub Stars: 3634
8.2.3 broken (SSL Handshake error) 8.2.1 I might be getting rate limited or there's some other issue. I am at least getting a handshake and response with 8.2.1 Adafruit CircuitPython 8.2.1 on 2023-07-25; Adafruit Feather ESP32S2 with ESP32S2
Board ID:adafruit_feather_esp32s2 ====== Circuit Python Internet Simple Test ======
Connecting to WiFi...
Connected!
{'message': "API rate limit exceeded for *IPADDRESS* (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)", 'documentation_url': 'https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting'}
Traceback (most recent call last):
File "code.py", line 30, in <module>
KeyError: stargazers_count
Code done running. Accidentally left print(response) on and 8.2.0 flooded with data and crashed my S2 and Mu. It returned so much data that I immediately got throttled with 8.2.1 but the server does respond with a nice error message. At least it's connecting. After that I went back to 8.2.0 just to see if I am getting rate limited and it'll throw the same error on a known good working version. It's giving the same rate limit error on 8.2.0 and 8.2.1 so I think we can call 8.2.1 good too. The problem is after 8.2.1 to 8.2.2. There are no beta releases between 8.2.1 to 8.2.2. I believe this issue could potentially affect any project (at least on S2/S3 modules) using Adafruit_Requests starting in 8.2.2 |
Here is a roots.pem that I generated a couple of weeks ago using the procedure described in https://github.com/arduino/nina-fw/blob/master/README.md#build-a-new-certificate-list-based-on-the-google-android-root-ca-list. When I substitute this one for the one in I think we should stop depending on nina-fw as a submodule, and just keep our own roots.pem, documenting how we built it. We could even write makefile steps to do that and verify it. |
I've been building the Pico W with the latest main branch bits and this evening was getting the "Sending request failed" message with one of my test programs. After building with the roots.pem file Dan posted the test program is working again. That being said, my test program was running fine when I built from main last night so I'm thinking the error only occurs when you hit a particular server somewhere in your path. I'll keep using the new roots.pem and if I hit any failures with it I'll update here. |
The change to After nina-fw is updated, the fix in CircuitPython will probably initially be made in 8.2.x and merged into main subsequent to that, though it depends on how Dan and/or Scott want to handle it. |
@DJDevon3 Just curious, did you try building the MatrixPortal S3 using the roots.pem file that Dan posted above? |
No, building circuit python isn't something I've done in a long time. :/ I'm not good with make builds. |
This is using the latest bits from main so it has the 1.19.1 Micropython merge included. MatrixPortal S3 UF2 with updated certificates: |
Is there a 9.0 alpha bundle? I'm getting Traceback (most recent call last):
File "code.py", line 7, in <module>
ValueError: incompatible .mpy file with 9.0.0-alpha.1-8-gaf91625fb-dirty It does not like the 8.2.3 adafruit_requests.mpy I have in lib edit: import os
import time
import ssl
import wifi
import socketpool
import adafruit_requests
pool = socketpool.SocketPool(wifi.radio)
JSON_STARS_URL = "https://api.github.com/repos/adafruit/circuitpython"
# Connect to Wi-Fi
print("\n====== MatrixPortal S3 WebClient Test ======")
print("Connecting to WiFi...")
requests = adafruit_requests.Session(pool, ssl.create_default_context())
while not wifi.radio.ipv4_address:
try:
wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))
except ConnectionError as e:
print("Connection Error:", e)
print("Retrying in 10 seconds")
time.sleep(10)
print("Connected!\n")
while True:
try:
response = requests.get(JSON_STARS_URL).json()
stargazers_count = response['stargazers_count']
print(f"CircuitPython GitHub Stars: {stargazers_count}")
except (ValueError, RuntimeError, OSError) as e:
print("Failed to get data, retrying\n", e)
time.sleep(60)
continue
response = None
print("Finished")
print("==============")
time.sleep(60) code.py output:
====== MatrixPortal S3 WebClient Test ======
Connecting to WiFi...
Connected!
CircuitPython GitHub Stars: 3643
Finished
============== Works with that 9.0 alpha build. That issue is definitely fixed in the alpha. Good job; 👍 |
@dhalbert @RetiredWizard Unsure if this can be closed now or not. Up to you. |
Use the .py files for now. We don't want to may a mpy bundle until 1.20 is merged because it changes the mpy format again. |
Thank you for the clarification. Already started transitioning the libraries on my 9.0 alpha boards to all py libraries and thus far everything is working as expected including the MatrixPortal S3. |
Just noting, this is still an issue in the the 9.0 pre-alpha builds (9.0.0-alpha.1-13-gc395e1f9f).
Adafruit_requests is an mpy for this specific commit. I build the mpy's directly for the version of circuitpython loaded on the board. |
Yep, until the actual fix is decided on, if you want to use SSL Requests with the latest main, you need to manually replace lib/certificates/nina-fw/data/roots.pem with Dan's roots.pem file. |
...or use: context = ssl.create_default_context()
context.load_verify_locations() with a CA string or .pem file |
I suppose the only reason it worked for me is because I used the firmware.zip @RetiredWizard posted above in here which has the updated roots.pem in the build. Thank you for making that build for me. I can live on that build until it gets merged with a stable release. |
I'm not sure if it's intended for a bundle (docs could be modified to indicate), just that it's sometimes used to get around a missing cert for a site, without requiring a custom build. |
Thanks for everything you all are doing. I struggled with this setting up a new Pico W today, trying to talk to the GitHub API. Based on the comments above, I simply downgraded to CircuitPython 8.2.0 and it immediately started working. |
I plan to release an 8.2.x with updated root certificates soon. |
Tested and confirmed fixed with 8.2.5 released today on the following boards
Thank you @dhalbert, issue closed. |
@tyeth Could you open a new issue about the bundle loading? Also try it on regular CPython, and try just one cert and more than one. |
Done, opened #8381 |
CircuitPython version
boot_out.txt
INFO_UF2.TXT
Code/REPL
Behavior
Description
Using Internet Test code from MatrixPortal S3 learn guide.
I have no problem viewing https://api.github.com/repos/adafruit/circuitpython with my browser. Shows all the JSON data fine. For whatever reason Github is failing to handshake with the MatrixPortal S3.
Additional information
This is only to report that a portion of code in a learn guide does not function correctly. I'm honestly not sure why it's failing.
Using adafruit_requests.mpy from adafruit-circuitpython-bundle-8.x-mpy-20230815
Matrix Portal is not connected to any matrix panels at this time. Using the board as I would a feather S3 with wifi.
I can get it to ignore the error with try/except but that's not the point in the case of learn guide code.
The text was updated successfully, but these errors were encountered: