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
urequests.get in Micropython randomly results in OSError 103 and 104 as well as ValueError #785
Comments
OSError 104 is url = "https://api.ecobee.com/1/thermostatSummary?format=json&body={\"selection\":{\"selectionType\":\"registered\",\"selectionMatch\":\"\",\"includeEquipmentStatus\":true}}"
headers = {
'Content-Type': 'text/json',
'Authorization': f'Bearer {accessToken}'
}
try:
response = urequests.get(url, headers=headers)
rstatus = response.status_code
data = response.json()
response.close()
except OSError, ValueError:
data = None
rstatus = 500 |
Hi Ned,
Thanks for the reply. I am already doing that and catching the OSError so I
can restart. OCError 104 is not too bad, but sometimes I get OSError 103
which occasionally can become sticky, where every following
urequest.get call will get the OSError 103. I increased the calls to
gc.collect() to free up memory in my loop. It reduced the frequency of
these errors, but they still pop up once every few hours and within a day,
it will turn sticky. Only way out was to do a machine.reset() and restart
the program after a soft boot.
It would be much easier to handle if urequest.get just returned with a
status code indicating the error instead of crashing with an exception 103
or 104.
Sammy
…On Thu, Jan 18, 2024 at 3:14 PM Ned Konz ***@***.***> wrote:
OSError 104 is ECONNRESET. Which can be caused by one end or the other
closing a socket too soon.
But one should usually enclose network functions in try/except blocks
anyway:
url = "https://api.ecobee.com/1/thermostatSummary?format=json&body={\"selection\":{\"selectionType\":\"registered\",\"selectionMatch\":\"\",\"includeEquipmentStatus\":true}}"headers = {
'Content-Type': 'text/json',
'Authorization': f'Bearer {accessToken}'
}try:
response = urequests.get(url, headers=headers)
rstatus = response.status_code
data = response.json()
response.close()except OSError, ValueError:
data = None
rstatus = 500
—
Reply to this email directly, view it on GitHub
<#785 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOBUR45SMZETAHI3OAVQYI3YPGUGRAVCNFSM6AAAAABBOA546CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJZGM3DMNZWGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am using urequest.get in Micropython running on a Raspberry Pi PICO W in a loop containing the following to access Ecobee's server for my furnace status:
This works most of the time, but the code will randomly crash with either OSError 104 or OSError 103 or ValueError. The following are REPL outputs of these errors.
I understand that the OSError 104 and 103 are network response issues. It would be much better if they can be handled with a returned status code rather than causing an OSError. According to the githib code at line 130 of request in requests/init.py, it is complaining about an invalid response presumabily from the internet response. Again, it would be more desirable to be handled with a status code response rather than causing a program crash.
The text was updated successfully, but these errors were encountered: