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

Tino Wildenhain tino@wildenhain.de
Wed, 20 Nov 2002 16:15:18 +0100


Hi,

--On Mittwoch, 20. November 2002 13:54 +0000 Duane Raymond 
<Duane.Raymond@Virgin.net> wrote:

> Hi,
>
> 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'm using an external method like this:

from ZPublisher import Client

def web_client(url, username =
None, password = None, **kw):
     '''access http servers'''
     class gen_res:
         __allow_access_to_unprotected_subobjects__=1
     f=gen_res()
     if kw:
         f.headers,f.body=apply(Client.call,(url,username,password),kw)
     else:
         f.headers,f.body=Client.call(url,username,password)
     return(f)


where you get an exception if status code cannot be handled
and have access to the returnvalues head (with headers)
and body (what comes back from server as content)

Regards
Tino