mechanize
mechanize copied to clipboard
No good way to tell when a timeout occurred
Got: When you request a timeout using the timeout parameter to urlopen (or Browser.open), in order to tell that a timeout occurred, you have to use a poorly-defined interface like HTTPError.reason, using code like this:
import mechanize import socket br = mechanize.Browser() try: br.open("http://python.org/", timeout=0.001) except mechanize.URLError, exc: if isinstance(exc.reason, socket.timeout): print "timeout occurred"
Expect: There's some clearly defined iinterface for finding out that a timeout imposed by module socket occurred.
Here's that snippet again, I hope formatted correctly this time:
import mechanize
import socket
br = mechanize.Browser()
try:
br.open("http://python.org/", timeout=0.001)
except mechanize.URLError, exc:
if isinstance(exc.reason, socket.timeout):
print "timeout occurred"
This is an issue inherited from urllib2.