Urllib3: Error decoding chunked response in _update_chunk_length

Created on 9 Oct 2018  路  7Comments  路  Source: urllib3/urllib3

Error decoding chunked response in _update_chunk_length: ValueError: invalid literal for int() with base 16: b'HTTP/1.1 200 OK\r\n'
Originally a Requests-Issue
Does the suggested fix, to check for the length, sound okay to you?
If so, I could just create a PR.

Most helpful comment

Can a more meaningful exception/error be raised than Error decoding chunked response in _update_chunk_length: ValueError: invalid literal for int() with base 16: b'HTTP/1.1 200 OK\r\n' - something which doesn't indicate a urllib3 bug?

All 7 comments

With proper unit tests I'd accept a PR with those changes.

Actually on second thought, I think it is legit to throw an exception in this situation

We temporarily repaired it in this way. I wonder if there will be any problem.

def _update_chunk_length(self):
    # First, we'll figure out length of a chunk and then
    # we'll try to read it from socket.
    if self.chunk_left is not None:
        return
    line = self._fp.fp.readline()
    line = line.split(b';', 1)[0]
    try:
        if len(line) == 0:
            self.chunk_left = 0
        else:
            self.chunk_left = int(line, 16)
    except ValueError:
        # Invalid chunked protocol response, abort.
        self.close()
        raise httplib.IncompleteRead(line)

I just thought it was fine to throw that exception when the connection was just closed and not data is left available. So this would need to be dealt with on a higher level (In this case requests).

Can a more meaningful exception/error be raised than Error decoding chunked response in _update_chunk_length: ValueError: invalid literal for int() with base 16: b'HTTP/1.1 200 OK\r\n' - something which doesn't indicate a urllib3 bug?

So is this issue a bug or not? If it's a bug instead of changing the error message I'd rather fix the issue.

Are there any public facing websites that always trigger this issue or do you have an example chunked body that causes it?

We use this on Lichess (https://lichess.org/) and all Lichess Bots go down due to this: https://github.com/careless25/lichess-bot/issues/163

Was this page helpful?
0 / 5 - 0 ratings