urllib: http error codes

P

Patrick Useldinger

Hi all,

I can't seem to get the http error codes back from urllib:
------------------------------------------------------------------'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML
2.0//EN">\n<HTML><HEAD>\n<TITLE>404 Not
{'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
 
P

Patrick Useldinger

Ok, found it myself...

class MyURLopener(urllib.FancyURLopener):
def http_error_default(self, url, fp, errcode, errmsg, headers):
void = fp.read()
fp.close()
raise IOError, ('http error', errcode, errmsg, headers)
urllib._urlopener = MyURLopener()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top