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: urllib does not handle Connection reset
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: fleiter, georg.brandl
Priority: normal Keywords:

Created on 2003-12-07 16:59 by fleiter, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg19297 - (view) Author: Stefan Fleiter (fleiter) Date: 2003-12-07 16:59
Python 2.2.3+ (#1, Nov 18 2003, 01:16:59)
[GCC 3.3.2 (Debian)] on linux2
 and 
Python 2.3.3c1 (#2, Dec  6 2003, 16:44:56)
[GCC 3.3.3 20031203 (prerelease) (Debian)] on linux2

Server which does reset Connection:
=====================
import SocketServer
class RequestHandler(SocketServer.BaseRequestHandler):
    def handle(self):
        self.request.send("")
server = SocketServer.TCPServer(("localhost", 2000),
RequestHandler)
server.serve_forever()

urllib-Code:
=======
import urllib
f = urllib.urlopen("http://localhost:2000")

Traceback:
=======
Traceback (most recent call last):
  File "url.py", line 4, in ?
    f = urllib.urlopen("http://localhost:2000")
  File "/usr/lib/python2.2/urllib.py", line 73, in urlopen
    return _urlopener.open(url)
  File "/usr/lib/python2.2/urllib.py", line 178, in open
    return getattr(self, name)(url)
  File "/usr/lib/python2.2/urllib.py", line 301, in
open_http
    return self.http_error(url, fp, errcode, errmsg,
headers)
  File "/usr/lib/python2.2/urllib.py", line 318, in
http_error
    return self.http_error_default(url, fp, errcode,
errmsg, headers)
  File "/usr/lib/python2.2/urllib.py", line 546, in
http_error_default
    return addinfourl(fp, headers, "http:" + url)
  File "/usr/lib/python2.2/urllib.py", line 824, in
__init__
    addbase.__init__(self, fp)
  File "/usr/lib/python2.2/urllib.py", line 778, in
__init__
    self.read = self.fp.read

The cause seems to be that urllib.addbase depends on
the fp argument beeing a valid socket while
    fp = h.getfile() in open_http sets it to None because
in httplib.HTTP.getreply() the
BadStatusLine-Exception-Handling was triggered.

urllib2 does handle this right.

Thanks for reading all of this. :-)
msg19298 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-14 08:31
Finally fixed in rev. 54376, 54377 (2.5). Now raises IOError.
History
Date User Action Args
2022-04-11 14:56:01adminsetgithub: 39674
2003-12-07 16:59:11fleitercreate