[Tutor] Testing for response from a Web site
Henry Steigerwaldt
hsteiger@comcast.net
Wed Apr 9 00:01:08 2003
To All:
How can I test the response of a server on a Web site to a
request that occurs when I attempt to access the Web site?
I am using the Windows XP operating system.
For example, if I select a link to a Web site, the server can
respond in (I think) only 3 different ways:
1) It can simply ignore the request.
2) It can honor the request and I can therefore download
some data, or...
3) It might send my PC some other response that I can
test for in a Python program, that tells the program that
the site is not accessible or available.
Here is the code I am using:
_________________________________________________
metURL = "http://isl715.nws.noaa.gov/tdl/forecast/tdl_etamet.txt"
f_object = open("c:\\python_pgms\\plot_guidance\\met_data.txt", 'w')
try:
print "\nBEGIN DOWNLOADING ETA (MET) MOS"
metall = urllib.urlopen(metURL).read()
f_object.write(metall)
f_object.close()
except:
print "Could not obtain data from Web"
f_object.close()
____________________________________________________
As it stands now, the program will just say the data is old, when I
really should say something like "could not connect with the site."
What additional test(s) can I perform to catch other responses from
a server, especially one in which the server will not honor my
request?
Thanks for any help.
Henry Steigerwaldt
Hermitage, TN
Email: hsteiger@comcast.net