catching exceptions while opening an URL

Doobee R. Tzeck drt at un.bewaff.net
Sat Nov 18 01:48:24 EST 2000


-$Paul$- at verence.demon.co.uk (Paul Wright) writes:

> In article <87itpmh8zv.fsf at c0re.bewaff.net>,
> Doobee R. Tzeck <drt-usenet-200011 at un.bewaff.net> wrote:
> >I'm trying to check if I can access a certain URL.
> >At the moment my code looks like this:
> ...
> >        try:
> >            h.putrequest('GET', path)
> >            h.putheader('Accept', 'text/html text/plain')
> >            h.endheaders()
> >        except:
> >            print "error: can't get %s Unexpected error: %s" %(url, sys.exc_info()[0])
> >            pass 
> >
> >
> >This works, but I don't want to catch any error, but just
> >socket.error(s). I didn't find a way to access socket.error
> >buried in httplib.HTTP.
> >
> >Any hints what I'm missing?
> 
> Urm... You're missing "import socket" at the top and "socket.error"
> after "except"
> 
> Or am I answering the wrong question here?

No, you anserwed the right question. Somehow I didn't
look for a global error variable but thought the error should be
somehow part of the HTTP Object.

Thanks a lot

drt

-- 
DC hat so einen cryptischen Syntax, den muß man einfach lieben.
                                                ---Ingo Schwitters
http://koeln.ccc.de/~drt/



More information about the Python-list mailing list