This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Fix for 767111, 'AttributeError thrown by urllib.open_http'
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, jerry.seutter, varmaa
Priority: normal Keywords: patch

Created on 2007-02-25 00:53 by varmaa, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
urllib_bug_767111_fix.diff varmaa, 2007-02-25 00:53 Fix for bug 767111
UrllibBug767111Tester.py varmaa, 2007-02-25 00:56 Unit test suite to consistently reproduce bug 767111
Messages (4)
msg51959 - (view) Author: Atul Varma (varmaa) Date: 2007-02-25 00:53
This is a fix for bug 767111:

http://sourceforge.net/tracker/index.php?func=detail&aid=767111&group_id=5470&atid=105470

I am also attaching a unit test that reliably reproduces the bug using an in-process web server.

I didn't want to modify httplib because it would mean altering its interface such that the HTTP.getfile() method would never return None, and that could break existing code.  So instead I modified urllib at a point that it appears to assume that HTTP.getfile() will always return a file object.  I hope this is a reasonable place to fix the problem, and I don't think it can break any existing code.  I also ran the existing "test/test_urllib.py" and "test/test_urllibnet.py" test suites and they both work fine with this patch.

Looking at the code, I also believe that a "parallel bug" exists with urllib.open_https(), and I fixed that as well (though I don't have a unit test to prove this).
msg51960 - (view) Author: Atul Varma (varmaa) Date: 2007-02-25 00:56
File Added: UrllibBug767111Tester.py
msg51961 - (view) Author: Jerry Seutter (jerry.seutter) * (Python committer) Date: 2007-03-06 07:34
Hi Atul,

I took a quick look at your patch and verified that the test case produces an AttributeError on trunk.  After manually patching urllib.py the test case passes.  A few observations:

1. Your patch changes the code from giving an AttributeError to giving an empty file back when the remote webserver gives a bad http status line.  The official Python documentation says that urlopen either generates an IOError when it can't connect to the server, or returns a file-like object when all goes well.  In this case all didn't go well, so the documentation is incomplete.  Would it be more appropriate to raise an exception rather than return an empty file?

2. I believe your test file will not work on systems without networking support.  Other Python tests that require networking support have this at the top of them:
test_support.requires('network')
See Lib/test/test_socketserver.py for example.

3. Consider merging your test into Lib/test/test_urllib.py and supplying a patch against that file.

4. Could the test be performed without actually getting a network connection?  Some of the tests in test_urllib.py use a FakeSocket class that might also work for your test.

5. Whitespace police - foo(arg1) instead of foo( arg1 ).  See PEP 8 at http://www.python.org/dev/peps/pep-0008/

Other than that, things look good.
msg51962 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-14 08:28
Fixed with a different patch in rev. 54376, 54377 (2.5).
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44612
2007-02-25 00:53:42varmaacreate