Using uasyncio server as HTTP Server: closing trouble #10745
-
Hello Micropython community. I'm new on Python and programming for a esp8266 and esp32 device. I'm programming a smartdevices, that connects to iobroker and has a webinterface for config. One of them is a uasyncio.start_server instance, which calls my function httpLoop:
The routines works fine on microsoft edge or with wget. But on Firefox the site generates successful but every time writer.close() will be called Firefox stop the site with "ERR_CONNECTION_RESET" (See Picture) The asycio.sleep() methods are only for debugging and trys to get fixed. I hope you can help me. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
You might like to look at the uasyncio source. await writer.wait_closed() This closes the socket. However at this point the writer has completed its work because you waited on |
Beta Was this translation helpful? Give feedback.
-
In my opinion it is bad practice to close sockets (or other resources) in a function that didn't open it. You can analyze FF's behaviour using it's web console. BTW, I don't understand all these asyncio.sleep() calls sprinkled around. I'm pretty sure asyncio will work as well without. There is no need to schedule other tasks before you |
Beta Was this translation helpful? Give feedback.
-
OK - i found a solution.
MUST for firefox be:
If you won't get everything from the clientbuffer. Firefox will stop with this error, because his connection will not be closed. The hole code to handle the HTML Request is:
|
Beta Was this translation helpful? Give feedback.
OK - i found a solution.
s = str(await reader.read(30))
MUST for firefox be:
s = str(await reader.read(-1))
If you won't get everything from the clientbuffer. Firefox will stop with this error, because his connection will not be closed.
The hole code to handle the HTML Request is: