[Tutor] Passing HTTP commands through Telnet using Python for web site testing?

Kent Johnson kent37 at tds.net
Thu Nov 17 13:57:31 CET 2005


Adisegna wrote:
> So far this is what I have come up with doing some research.
> 
> import urllib
> for line in urllib.urlopen('http://mywebsit.com/folder/folder/test.asp'):
>  if '400 Bad Request' in line:     
> 
>     text_file = open("mysite.log", "a")
> text_file.writelines(line)
> text_file.writelines("\n")
> text_file.close()

You are counting on the HTTP status code being part of the body of the response. This will depend on the details of the server. Better is to look at the actual HTTP status. Here is an example of retrieving a page with urllib2 and capturing HTTP status codes:
http://mail.python.org/pipermail/python-list/2003-July/175455.html

Kent

-- 
http://www.kentsjohnson.com



More information about the Tutor mailing list