Bugs item #1593751, was opened at 2006-11-09 21:04 Message generated for change (Comment added) made by gbrandl You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1593751&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed >Resolution: Fixed Priority: 5 Private: No Submitted By: Guido van Rossum (gvanrossum) Assigned to: Nobody/Anonymous (nobody) Summary: poor urllib error handling Initial Comment: I set up a simple server that returns an empty response. >>> from socket import * >>> s = socket() >>> s.bind(("", 9999)) >>> while 1: x, c = s.accept(); print c; x.recv(1000); x.close() ... Pointing urllib at this gives a traceback: Python 2.6a0 (trunk:52099M, Oct 3 2006, 09:59:17) [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib >>> urllib.urlopen('http://localhost:9999/') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/guido/p/Lib/urllib.py", line 82, in urlopen return opener.open(url) File "/home/guido/p/Lib/urllib.py", line 190, in open return getattr(self, name)(url) File "/home/guido/p/Lib/urllib.py", line 334, in open_http return self.http_error(url, fp, errcode, errmsg, headers) File "/home/guido/p/Lib/urllib.py", line 351, in http_error return self.http_error_default(url, fp, errcode, errmsg, headers) File "/home/guido/p/Lib/urllib.py", line 608, in http_error_default return addinfourl(fp, headers, "http:" + url) File "/home/guido/p/Lib/urllib.py", line 951, in __init__ addbase.__init__(self, fp) File "/home/guido/p/Lib/urllib.py", line 898, in __init__ self.read = self.fp.read AttributeError: 'NoneType' object has no attribute 'read' >>> I can repeat this with 2.2.3 and 2.4.3 as well (don't have 2.3 around for testing). The direct cause of the problem is that h.getfile() on line 329 of urllib.py (in head of trunk) returns None. ---------------------------------------------------------------------- >Comment By: Georg Brandl (gbrandl) Date: 2007-03-14 08:30 Message: Logged In: YES user_id=849994 Originator: NO Finally fixed in rev. 54376, 54377 (2.5). ---------------------------------------------------------------------- Comment By: Robert Winder (robertwinder) Date: 2006-12-15 16:15 Message: Logged In: YES user_id=195085 Originator: NO Same error handling with 2.3. Suggested fix doesn't work and gives. AttributeError: addinfourl instance has no attribute 'read' ---------------------------------------------------------------------- Comment By: Robert Carr (racarr) Date: 2006-12-05 15:26 Message: Logged In: YES user_id=1649655 Originator: NO Fix? Index: urllib.py =================================================================== --- urllib.py (revision 52918) +++ urllib.py (working copy) @@ -895,8 +895,10 @@ def __init__(self, fp): self.fp = fp - self.read = self.fp.read - self.readline = self.fp.readline + try: + self.read = self.fp.read + self.readline = self.fp.readline + except: print "File handler is none" if hasattr(self.fp, "readlines"): self.readlines = self.fp.readlines if hasattr(self.fp, "fileno"): self.fileno = self.fp.fileno ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1593751&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com