Issue 1680230: urllib.urlopen() raises AttributeError (original) (raw)

When you connect urlopen() to a socket that does not send any data, it produces an AttributeError.

File "/lib/python2.6/urllib.py", line 608, in http_error_default return addinfourl(fp, headers, "http:" + url) File "/lib/python2.6/urllib.py", line 951, in init addbase.init(self, fp) File "/lib/python2.6/urllib.py", line 898, in init self.read = self.fp.read AttributeError: 'NoneType' object has no attribute 'read'

Raising an exception is OK (I think?), but it should be an IOError instead of an AttributeError. See the attached patch for a test case for the bug.