Message140569
| Author |
vstinner |
| Recipients |
daniel.ugra, nadeem.vawda, orsenthil, santoso.wijaya, vstinner |
| Date |
2011年07月18日.09:00:38 |
| SpamBayes Score |
9.409613e-05 |
| Marked as misclassified |
No |
| Message-id |
<1310979639.88.0.917353203934.issue12576@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
h.close() (HTTPConnection.close) in the finally block of AbstractHTTPHandler.do_open() calls indirectly r.close() (HTTPResponse.close). The problem is that the content of the response cannot be read if its close() method was called.
The changelog of the fix (commit ad6bdfd7dd4b) is: "Issue #12133: AbstractHTTPHandler.do_open() of urllib.request closes the HTTP connection if its getresponse() method fails with a socket error. Patch written by Ezio Melotti."
The HTTP connection is not only closed in case of an error, but it is always closed.
It's a bug because we cannot read the content of www.imdb.com, whereas it works without the commit. Test script:
---------------
import urllib.request, gc
print("python.org")
with urllib.request.urlopen("http://www.python.org/") as page:
content = page.read()
print("content: %s..." % content[:40])
gc.collect()
print("imdb.com")
with urllib.request.urlopen("http://www.imdb.com/") as page:
content = page.read()
print("content: %s..." % content[:40])
gc.collect()
print("exit")
--------------- |
|