-
Notifications
You must be signed in to change notification settings - Fork 138
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
Issue with requests partial read #8
Comments
Hi @Reboare , This is a very rare issue. I remember it was reported one time before, but the solution was indirect and could lead to further errors. I'm not sure how to fix this issue in the best possible approach |
Thanks for the reply, I'm going to have a play around and see if I can find the fix it. What was the indirect solution? |
Here is the previous solution for the issue:
|
Great! Feel free to check it, and please let me know if you find another approach for solving the issue |
I've found a few approaches. It seems requests doesn't handle IncompleteRead's well at all and will happily throw away any data it finds. One involves re-implementing in urllib2, which is far from ideal. Alternatively re-raising a request in the event of a ChunkedEncodingError, which will then handle the IncompleteRead is possible, but then it means sending two connection requests each time, which is a bit messy. I could add a flag to allow handling this, but that's really just adding cruft. The only other solution I can see is very similar to the above although I've tried to clean it up a bit and add correct error handling: try:
with requests.get(url, headers=headers, timeout=timeout, allow_redirects=False, stream=True) as rq:
output = ""
for i in rq.iter_content():
output += i
except requests.exceptions.ChunkedEncodingError as e:
print("EXCEPTION::::--> " + str(e))
print("Server is prematurely closing connection!")
except Exception as e:
print type(e)
print("EXCEPTION::::--> " + str(e))
output = 'ERROR'
return(output) By delaying the request to later and then reading the content byte by byte, this should handle closing the request healthily by wrapping it within the Would you be happy with this solution if I were to clean it up and submit a pull? Effectively it's acting in a similar manner to under the hood, and I'm more than happy to add the stuff |
Hi @Reboare , This will be a great addition!. I would be totally happy implementing your solution to the repo. Once you make a pull request, I will test it on a local testing VM and then merge it to master. Thanks again for your time and interest! |
Urls have been obfuscated. On a vulnerable struts server, using the default struts-pwn, an IncompleteRead is returned with 0 bytes
If this is swapped to be urllib2 however, a partial response is received:
I've yet to identify what behind the scenes is causing this error. Urllib3 appears to have the same behaviour as urllib2 (although I can't work out how to decode the response). Any idea if the way requests is working is causing issues?
The text was updated successfully, but these errors were encountered: