[issue10577] (Fancy) URL opener stuck when trying to open redirected url
Antoine Pitrou
report at bugs.python.org
Mon Nov 29 18:51:35 CET 2010
Antoine Pitrou <pitrou at free.fr> added the comment:
I can reproduce the issue with 3.2 here. Using Wireshark, I see that the request to http://www.ihnez.cz is satisfied, but the second request (to http://ihnez.cz) is never issued. Here is the Wireshark dump for the TCP session (request, then response):
"""GET / HTTP/1.1
Accept-Encoding: identity
Host: www.ihned.cz
User-Agent: Python-urllib/3.2
HTTP/1.1 302 Found
Server: nginx
Date: Mon, 29 Nov 2010 17:41:23 GMT
Content-Type: text/html; charset=WINDOWS-1250
Transfer-Encoding: chunked
Connection: keep-alive
Location: http://ihned.cz/
0
"""
Looking at the traceback when pressing Control-C, it seems the redirect handler in urllib expects the socket to be closed by the server, but it isn't; so it keeps waiting for more data (despite the "0" signifying the end of the chunked response):
>>> import urllib.request
>>> opener = urllib.request.FancyURLopener()
>>> f = opener.open("http://www.ihned.cz/")
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/antoine/py3k/__svn__/Lib/urllib/request.py", line 1504, in open
return getattr(self, name)(url)
File "/home/antoine/py3k/__svn__/Lib/urllib/request.py", line 1676, in open_http
return self._open_generic_http(http.client.HTTPConnection, url, data)
File "/home/antoine/py3k/__svn__/Lib/urllib/request.py", line 1672, in _open_generic_http
response.status, response.reason, response.msg, data)
File "/home/antoine/py3k/__svn__/Lib/urllib/request.py", line 1688, in http_error
result = method(url, fp, errcode, errmsg, headers)
File "/home/antoine/py3k/__svn__/Lib/urllib/request.py", line 1876, in http_error_302
data)
File "/home/antoine/py3k/__svn__/Lib/urllib/request.py", line 1887, in redirect_internal
void = fp.read()
File "/home/antoine/py3k/__svn__/Lib/socket.py", line 267, in readinto
return self._sock.recv_into(b)
KeyboardInterrupt
However, urllib.request.urlopen() works fine in this case, so perhaps this advocates for deprecating the old stuff? Senthil?
----------
assignee: -> orsenthil
nosy: +orsenthil, pitrou
versions: +Python 2.7, Python 3.2
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10577>
_______________________________________
More information about the Python-bugs-list
mailing list