micropython / micropython/micropython-lib
_thread Issue with HTTPS
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 2.9k
- Forks
- 1.1k
- Ø Merge
- 7 T. 6 Std.
- Gemergte PRs (30 T.)
- 3
Beschreibung
I've been using _thread to run a background task, and at one point the background task posts some data online (so, connects to the wifi, HTTP request and print the result). First time it works well, but whenever I repeat it, I tend to get a number of errors, the main one being
mbedtls_ssl_handshake error: -4290
and
File "urequests.py", line 111, in post
File "urequests.py", line 96, in request
File "urequests.py", line 60, in request
OSError: [Errno 5] EIO
I assume this has something to do with the thread trying to access the wifi twice, as it works the first time, every time, but 2nd time around, no joy.
I have tried wlan.disconnect(), and wlan.active(False) to disable the wifi in between requests, but without much joy.
This is my function:
def postJSON(j, url, retries=0, max_retries=4):
data = ujson.dumps(j)
if retries < max_retries: # Only retry the connection 3 times, otherwise, give up TODO: Don't give up silently!
wlan = network.WLAN(network.STA_IF)
if wlan.isconnected(): # Check connection
print(data)
r = requests.post(url=url, json=j, headers={"Authorization": "Basic " + authkey})
if (r.status_code == 200): # Check if the response OK
print("success")
wlan.disconnect()
return True
else: # Otherwise, retry
postJSON(j, url, retries+1)
else:
do_connect()
postJSON(j, url, retries+1)
else:
print("Tried 4 times, and failed. Sorry\r\nGiving Up")
return False
Running this on the main thread throws up no such issues.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie damit, die Anfrage im _thread-Hintergrund mithilfe der bereitgestellten Funktion postJSON zu reproduzieren. Lesen Sie anschließend urequests.py ungefähr bei den Zeilen 60, 96 und 111 und untersuchen Sie die Aufrufe von network.WLAN und do_connect. Vergleichen Sie wiederholte Anfragen aus dem Hauptthread und dem Hintergrundthread, einschließlich des gemeldeten mbedtls_ssl_handshake-Fehlers und von OSError. Als erledigt gilt die Aufgabe, wenn die wiederholte Thread-HTTPS-Anfrage zuverlässig abgeschlossen wird oder der Fehler mit bestätigtem Umfang dokumentiert ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- embedded-iot, networking
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100