Skip to content
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

rewind file body for retry send request #321

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

rewind file body for retry send request #321

wants to merge 2 commits into from

Conversation

gmixo
Copy link

@gmixo gmixo commented Dec 12, 2015

Hello guys!

Recently I recived some strange behavior for sending http requests using httplib2

My python script uses httplib2 and interacts with a web server which have a keep-alive timeout 5 seconds. Script makes PUT requests and sends files to server. At first time it works ok. Then after 5 seconds server closes connection. And then I doing second PUT request, that fails in two stages:

  • HTTPConnectionWithTimeout trys to send PUT request to closed socket.
  • HTTPConnectionWithTimeout reconnects to server and sends request again but no file sended.
    This behavior was checked using wireshark and debug output of httplib.

This issue is on border of interacting httplib and httplib2

  • httplib sends request and reads out a file
  • httplib2 resends a request but file is already readed out

@parabolala
Copy link

Note that it seem to make more sense to:
a) if the body supports .tell(), on retry it should be rewinded to the initial position that was passed on first invocation
b) if the body doesn't support tell/seek, then exception should be raised explicitly if some data was attempted to be sent, but failed and so is not recoverable.

@gmixo
Copy link
Author

gmixo commented Dec 18, 2015

well I could rewrite patch in such case

if hasattr(body, 'read') and body.tell() > 0:
    body.seek(0) # rewind for retry send file

since httplib file data sending is based on assumption that object have a read method we could check the same and just do what we do and if it fails it will raise an exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants