Lost between urllib and httplib

Toby Dickenson tdickenson at devmail.geminidataloggers.co.uk
Tue Jun 12 09:04:21 EDT 2001


On 10 Jun 2001 21:06:11 GMT, gustafl at algonet.se (Gustaf Liljegren)
wrote:

>I'm choosing between urllib and httplib, but have trouble with both. 
>urllib.urlopen() is hiding HTTP errors (hope this will be fixed in next 
>version!)

urllib.urlopen is implemeneted using the class urllib.FancyURLopener.
That class does lots of good things (such as transparently handing
redirects) but its default behaviour is to swallow any errors it
doesnt know how to handle.

I suggest you derive a new class from FancyURLopener, and overide the
http_error_default function. I often use this class to raise errors in
exceptions.....

class URLopener(urllib.FancyURLopener):
    def http_error_default(self, url, fp, errcode, errmsg, headers):
        return urllib.URLopener.http_error_default(self, url, fp,
errcode, errmsg, headers)



>and httplib.HTTP() doesn't seem to be able to access some pages 
>if you only supply a domain name.

httplib is very low level, I suggest you stick with urllib.



Toby Dickenson
tdickenson at geminidataloggers.com



More information about the Python-list mailing list