micropython / micropython/micropython-lib
_thread Issue with HTTPS
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 2.9k
- Fork
- 1.1k
- Merge medio
- 7g 6h
- PR unite (30g)
- 3
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo la richiesta in background di _thread usando la funzione postJSON fornita, quindi leggi urequests.py intorno alle righe 60, 96 e 111 e analizza le chiamate a network.WLAN e do_connect. Confronta le richieste ripetute dal thread principale e dal thread in background, incluso l’errore mbedtls_ssl_handshake e OSError segnalati. Il lavoro è completato quando la richiesta HTTPS ripetuta dal thread termina in modo affidabile oppure il problema è documentato con un ambito confermato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- embedded-iot, networking
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100