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

raise requests.exceptions.ReadTimeout for streaming responses #4882

Closed
wants to merge 2 commits into from

Conversation

bgardiner
Copy link

Currently, if there is a read timeout while streaming a response, a requests.exceptions.ConnectionError is raised in lieu of a requests.exceptions.ReadTimeout. This is unexpected and contrary to the documentation. As a user, I am being forced to catch the ConnectionError when I only actually care about the ReadTimeout situation.

This PR revises the streaming response code to properly raise a requests.exceptions.ReadTimeout, consistent with the non-streaming request behavior.

I am unable to write a test for this situation since httpbin does not support a delay for chunked-encoded responses; see postmanlabs/httpbin#479 regarding this lack of functionality.

raise raise requests.exceptions.ReadTimeout for a urllib3.ReadTimeoutError in streaming responses
@bgardiner
Copy link
Author

Any thoughts on this? I think this is clearly a bug in the existing implementation...... is there something I am missing?

@bgardiner
Copy link
Author

ping anyone want to take a look at this?

@Mr0grog
Copy link

Mr0grog commented Dec 16, 2020

I looks like this has been fixed in the 3.0 branch, and the comments on #2392 and #5430 note that a change like this is too much of a breaking change to ship with 2.x. So maybe this should be closed? (With an explanation for people encountering the issue, please!)

FWIW, though, I got here because I only recently had time to really dig into Requests and Urllib3 to understand what was happening here — this has been a longstanding issue in a codebase I maintain, where we were successfully catching some read timeouts but not others. I definitely understand I don’t speak for all users, but, like @VasiliPupkin256, having this fix in 2.x would not break me and would actually really help me clean up some messy code by making error handling more consistent (I currently catch both Timeout and ConnectionError, but for the latter case inspect the error string to decide what to do, which is really not good).

@nateprewitt nateprewitt changed the base branch from master to main January 3, 2022 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants