[Zope] How do I get remote http error code?

Duane Raymond Duane.Raymond@Virgin.net
Wed, 20 Nov 2002 15:55:59 -0000


Never mind - I just found an answer to my own question - it is posted below
if anyone else needs it at some point

> I'm struggling to find a way to return the http error code (i.e.
> 404, 401, 301, 201) using an External Script and urllib.
>
> I can read the file using urllib.urlopen(url).read() and can get
> general info using  urllib.urlopen(url).info() - however I can't
> find how to return the error code (i.e if the remote page doesn't exist).
>
> Anyone know how to resolve this?

I used httplib (adapting code from
http://www.python.org/doc/lib/httplib-examples.html)

    conn = httplib.HTTPConnection(urldomain)
    conn.request("GET", urlpath)
    r1 = conn.getresponse()
    pgStatus = [r1.status, r1.reason]

where urldomain = domain name (www.xyz.com) and urlpath is any bit after the
domain.

Cheers,

Duane