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

ChunkedEncodingError isn't explained properly #4771

Closed
ron819 opened this issue Aug 26, 2018 · 1 comment
Closed

ChunkedEncodingError isn't explained properly #4771

ron819 opened this issue Aug 26, 2018 · 1 comment

Comments

@ron819
Copy link

ron819 commented Aug 26, 2018

The docs says about ChunkedEncodingError:

class ChunkedEncodingError(RequestException):
    """The server declared chunked encoding but sent an invalid chunk."""

While this true it's highly confusing. What actually happens is that the server did not respond in time so the connection was closed. The solution is to retry the code and attempt again:

    def get(tries=5):
        for n in range(tries):
            try:
                GET call
                return whatever
            except ChunkedEncodingError as e:
                if n == tries - 1:
                    raise e

This has been asked many time over the internet including even here: #4484

I recommend adding an optional argument for the GET call which will specify the tries number and that will be handled by the get call itself. This will avoid this problem and allow the user more control.
meaning that the GET will return the exception only when the max retries has been reached.

If my suggestion is not accepted at least edit the docs and suggest the template of the solution to avoid the problem.

@nateprewitt
Copy link
Member

Hi @ron819, while the exception we're wrapping isn't the clearest, it does convey the connection has been broken with the server. The cause of that could be a multitude of things, but is likely the server forcing the connection closed.

requests.exceptions.ChunkedEncodingError: ("Connection broken: error(10054, '')", error(10054, ''))

I don't think it's clear that most users would want to retry in the case of a misbehaving server. Our API for Requests is currently frozen, so changes to the get method are unlikely unless there's significant oversight in functionality. Your example shows this should be easily implementable in 10-15 lines of code in your application, giving your complete control over how it will work. For those reasons, I don't think we'll be adding anything new to the Requests code base at this time.

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

No branches or pull requests

2 participants