urllib2 http status
rosendo
rosendo at dbora.com
Tue Jul 29 13:16:08 EDT 2003
I'm writing a http client to test some applications.
The code below it's the core of the client:
try:
start_ts = time.time()
request = urllib2.Request('http://%s%s'
%(req.host,req.path), req.data, req.headers)
request.add_header("Referer", 'http://%s%s'
%(req.host,req.path))
c.add_cookie_header(request)
c.clear()
#request = urllib2.Request('http://www.google.com')
try:
response = urllib2.urlopen(request)
data = response.read()
headers = response.info().headers
#status = response.info().status
d = c.extract_cookies(response, request)
except urllib2.URLError, msg:
print "URLError: ", msg;
except urllib2.HTTPError, msg:
print "HTTPError: ", msg;
except:
print sys.exc_type,sys.exc_value
duration = time.time() - start_ts
print 'The result had status: %s duration: %5.2f
http://%s%s' %(response.info().status, duration, req.host,req.path)
except:
print sys.exc_type,sys.exc_value
print 'cagadita....' + str(req)
Before this code we declare c = ClientCookie.Cookies(), etc......
Then i don't know how to know the status of the response, because the
property:
response.info().status seems not to function like i wait, that it's
with an 200, 301, 400, etc.....
How can obtein this status?
I prefer not use httplib, but with urllib2 i'm not sure if i could
obtain the HTTP status.
Thanks in advance.
Rosendo.
More information about the Python-list
mailing list