urllib: http error codes

Patrick Useldinger p at trick.lu
Thu Dec 18 15:26:24 EST 2003


Hi all,

I can't seem to get the http error codes back from urllib:
------------------------------------------------------------------
>>> import urllib
>>> f = urllib.urlopen(r'http://www.pt.lu/nowhere')
>>> f.read()
'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML
2.0//EN">\n<HTML><HEAD>\n<TITLE>404 Not
Found</TITLE>\n</HEAD><BODY>\n<H1>Not Found</H1>\nThe requested URL
/nowhere was not found on this server.<P>\n</BODY></HTML>\n'
>>> f.geturl()
'http://www.pt.lu/nowhere'
>>> i=f.headers
>>> i.dict
{'date': 'Thu, 18 Dec 2003 20:19:16 GMT', 'connection': 'close',
'content-type': 'text/html; charset=iso-8859-1', 'server':
'Apache/1.3.27 (Unix) mod_jk/1.1.0 PHP/4.3.2 mod_perl/1.27
mod_layout/3.2'}
------------------------------------------------------------------
I expected to have an IOException with a code 404 (according to the
doc).
Is this due 
- to the webserver, i.e. is it *not* returning the expected error code,
- am I doing something wrong here?

-Patrick
--
http://www.homepages.lu/pu/




More information about the Python-list mailing list