mechanize icon indicating copy to clipboard operation
mechanize copied to clipboard

No good way to tell when a timeout occurred

Open jjlee opened this issue 16 years ago • 2 comments

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.

jjlee avatar Nov 27 '09 11:11 jjlee

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"

jjlee avatar Nov 27 '09 11:11 jjlee

This is an issue inherited from urllib2.

jjlee avatar Nov 27 '09 11:11 jjlee