Package: python2.5
Version: 2.5.4-1
Severity: normal

Hi,

A bug has been posted against urlwatch:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=529740

It looks like there is a problem in urllib2.

To reproduce it, you can run the following HTTP server

[quote = http_server]
import BaseHTTPServer
class BrokenRequestHandler (BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET (self):
        self.wfile.write("")
if __name__ == '__main__':
    handler_class=BrokenRequestHandler
    server_address = ('', 80)
    httpd = BaseHTTPServer.HTTPServer(server_address, handler_class)
    httpd.serve_forever()
[/quote]

With this script on the client side:

[quote = client]
req = urllib2.Request("http://192.168.2.2/index.html";,)
try:
    urllib2.urlopen(req)
except (urllib2.URLError), err:
    print err
else:
    print "OK"
[/quote]

We get:

[quote=error]
Traceback (most recent call last):
  File "./bug_529740.py", line 8, in <module>
    urllib2.urlopen(req)
  File "/usr/lib/python2.5/urllib2.py", line 124, in urlopen
    return _opener.open(url, data)
  File "/usr/lib/python2.5/urllib2.py", line 381, in open
    response = self._open(req, data)
  File "/usr/lib/python2.5/urllib2.py", line 399, in _open
    '_open', req)
  File "/usr/lib/python2.5/urllib2.py", line 360, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.5/urllib2.py", line 1107, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.5/urllib2.py", line 1080, in do_open
    r = h.getresponse()
  File "/usr/lib/python2.5/httplib.py", line 928, in getresponse
    response.begin()
  File "/usr/lib/python2.5/httplib.py", line 385, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.5/httplib.py", line 349, in _read_status
    raise BadStatusLine(line)
httplib.BadStatusLine
[/quote]

If we catch httplib.HTTPException:

 except (urllib2.URLError, httplib.HTTPException), err:

then, it is fine.

I think this error should be caught by urllib2.URLError.
Any thoughts ?

Regards,

-- 
Franck Joncourt
http://debian.org - http://smhteam.info/wiki/

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to