[New-bugs-announce] [issue2645] httplib throws ValueError

Niall O'Higgins report at bugs.python.org
Wed Apr 16 20:16:00 CEST 2008

New submission from Niall O'Higgins <niallo at unworkable.org>:

I do a lot of urllib2 reads of HTTP URLs.  From time to time, I see the
following exception being thrown:

  File "/usr/local/lib/python2.5/socket.py", line 291, in read
    data = self._sock.recv(recv_size)
  File "/usr/local/lib/python2.5/httplib.py", line 509, in read
    return self._read_chunked(amt)
  File "/usr/local/lib/python2.5/httplib.py", line 548, in _read_chunked
    chunk_left = int(line, 16)
ValueError: invalid literal for int() with base 16: ''

The chunked reading code does not expect an empty string.  I have
attached a patch which checks for ValueError in this case and sets
chunk_left to 0, which will break from the loop.  I am not entirely sure
if this is the correct fix, however, but it should illustrate the problem.

components: Library (Lib)
files: httplib.py.diff
keywords: patch
messages: 65557
nosy: niallo
severity: normal
status: open
title: httplib throws ValueError
type: behavior
versions: Python 2.5
Added file: http://bugs.python.org/file10040/httplib.py.diff

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list