Getting server status response from HTTP request

Mike C m at
Fri Feb 13 19:36:44 CET 2004

First of all, I am a complete newbie to Python, but have been impressed 
with how easy the language has been to pick up.

I am trying to write a script that checks to see if the web / 
application server is up. I have the following code that works:

import httplib

     httpobj = httplib.HTTPConnection('', 80)
     httpobj.putrequest('GET', '/foo/ping.cfm')
     httpobj.putheader('Accept', '*/*')

     reply = httpobj.getresponse()

     if reply.status != 200:
     	print "There may be a problem with the server. Response Status :", 
     	print "server is fine"
except Exception:
     print "An exception occured"

I was curious if anyone had suggestions on a better way to do this. I 
tried to use urllin2, but could not figure out how to retrieve the 
status code.

mike c

More information about the Python-list mailing list