urequests error

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
danielm
Posts: 167
Joined: Mon Oct 05, 2015 12:24 pm

urequests error

Post by danielm » Sat Jul 30, 2016 7:12 am

I am using latest urequests from micropython-lib.
In some rare cases (once in few hours for requests performed repeatedly every second) I get empty response without any header:

{"AirTemperature":23, "FanRpm":0, "MemoryFree":36960, "MemoryAllocated":20656, "DeviceStartup":false, "Error":null}
b'HTTP/1.1 200 OK\r\n'
{"AirTemperature":23, "FanRpm":0, "MemoryFree":36960, "MemoryAllocated":20656, "DeviceStartup":false, "Error":null}
b'HTTP/1.1 200 OK\r\n'
{"AirTemperature":23, "FanRpm":0, "MemoryFree":36960, "MemoryAllocated":20656, "DeviceStartup":false, "Error":null}
b''
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "main.py", line 294, in reportStatus
File "main.py", line 283, in reportStatus
File "/flash/lib/urequests.py", line 108, in put
File "/flash/lib/urequests.py", line 78, in request
ValueError: wrong number of values to unpack
>>>

This empty response obviously causes failure of following line from urequests.py:
protover, status, msg = l.split(None, 2)

The server was tested for several days with another client and there was no case of empty response therefore I started suspect my client side (WiPy MicroPython).

Do you have any idea what could cause that there is no response to be read from the socket?

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: urequests error

Post by pfalcon » Sun Jul 31, 2016 1:43 pm

Empty response means that a client socket was closed, which means server closed it or some networking error occurred. As any networking is by definition non-reliable, such errors are bound to occur, and do occur everywhere (with different probability of course). Sure, the module should be prepared for that too and don't handle it like the above. I'll try to research the best way to handle it.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

danielm
Posts: 167
Joined: Mon Oct 05, 2015 12:24 pm

Re: urequests error

Post by danielm » Sun Jul 31, 2016 4:47 pm

Thanks a lot for your effort. I am sure this module will be used widely.

Post Reply