Martin Panter <vadmium...@gmail.com> added the comment:

Previous report about Requests to the Python bug tracker: Issue 33620.

I suspect this is an unavoidable race condition with trying a POST (or other 
non-idempotent) request on an idle HTTP connection. I think it has to be up to 
the higher-level application or user to decide if it is safe to retry a POST 
request. Otherwise you risk e.g. accidentally ordering two pizzas because the 
server received two POST requests but something interfered with the response of 
the first response. On the other hand, I noticed some browsers seem to 
automatically retry a POST once if it is interrupted, which makes me uneasy.

A concrete example of the problem is a firmware upload that triggers a reboot. 
If the reboot is too quick and prevents the POST response being sent, I found 
that a web browser will repeat the firmware upload once more after my firmware 
boots up again.

If it is not safe to retry the POST request, other options would be to avoid 
the server thinking the connection is stale:

* always do the POST request on a fresh HTTP connection
* "ping" the connection with a dummy request (e.g. OPTIONS, HEAD, or GET) 
immediately before the POST request

Another option that comes to mind is to try using the 100 Continue mechanism, 
but this is not a general solution and depends on the application.

----------
nosy: +martin.panter

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41345>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to