Very peculiar on-off issue with urequests
Posted: Fri Nov 15, 2019 1:48 am
I've got a pyboard D which talks to a web service using `urequests`. The communications aren't that complicated; it sends a get request and receives a short bit of json in in retun, something like this:
This all works.... slightly less than 50% of the time. One pattern I have been able to repro is that it works on alternating runs, ie, if i power up the pyboard it will work (as far as I can tell, for that entire session) but if the board is powered off and then powered back on it won't work at all in the next session: all requests will fail with an , i think always with a -2 error code.
Restart again, and it works.
The truly puzzling thing is that the code which runs this is basically stateless (it does not save information to so I don't have the faintest idea how I could be inadvertently setting up an even-odd error situation. However the repro is vey solid, I've verified it dozens of times on... off... on... off....
I've tried:
The part of the loop which is trying to talk to the server is like this;
AFAICT all of the failure are OSError -2 in either the get or the json() line.
Code: Select all
{"remaining": 123, "total": 456}
Code: Select all
OSError
Restart again, and it works.
The truly puzzling thing is that the code which runs this is basically stateless (it does not save information to
Code: Select all
/flash
I've tried:
- waiting in between runs, in cases there's some kind of sticky state. Waits up to the limits of my patience (5 mins or so) seem to have no effect
- looking at the logs for the server to see if there anomalies in the requests. They appear to be well-formed
Code: Select all
75.172.128.250 - - [15/Nov/2019:01:22:25 +0000] "GET /check/Dad HTTP/1.1" 200 32 "-" "-" "75.172.128.250" response-time=0.002
- adding code to make sure the NIC is still connected. It is.
The part of the loop which is trying to talk to the server is like this;
Code: Select all
if LOGGED_IN is not None and len(LOGGED_IN):
req = 'http://theodox.pythonanywhere.com/check/{}'.format(LOGGED_IN)
print("checking status")
response = None
try:
response = requests.get(req)
info = response.json()
except OSError:
error = "request timeout"
print(error)
LOGGED_IN = None
REMAIN = 0
TOTAL = 0
time.sleep(1)
else:
REMAIN = info['remaining']
TOTAL = info['total']
finally:
del response