Message140569
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")
--------------- |
|
Date |
User |
Action |
Args |
2011-07-18 09:00:40 | vstinner | set | recipients:
+ vstinner, orsenthil, nadeem.vawda, daniel.ugra, santoso.wijaya |
2011-07-18 09:00:39 | vstinner | set | messageid: <1310979639.88.0.917353203934.issue12576@psf.upfronthosting.co.za> |
2011-07-18 09:00:39 | vstinner | link | issue12576 messages |
2011-07-18 09:00:38 | vstinner | create | |
|