[Tutor] Passing HTTP commands through Telnet using Python for web site testing?
kent37 at tds.net
Thu Nov 17 12:13:49 CET 2005
> I just started learning Python and would like to try writing a
> monitoring script.
> What I would like to do is use Telnet to send a GET via port 80 to a
> status page in a directory to verify my site is up.
I use httplib for this. You can probably do it with urllib2 also but I don't know how to get the status codes from urllib2.
Here is an incomplete snippet:
if self.method == 'http':
conn = HTTPConnection(self.server)
conn = HTTPSConnection(self.server)
resp = conn.getresponse()
data = resp.read()
status = resp.status
if status == 200:
success = self.successText in data
clientErrorMsg = 'Ping failed due to timeout (%s seconds)' % timeout
except socket.error, msg:
clientErrorMsg = 'Ping failed with error ' + str(msg)
clientErrorMsg = ''.join(traceback.format_exception(*sys.exc_info()))
More information about the Tutor