Timeouts with urllib2
Fazer
faizan at jaredweb.com
Tue Mar 16 16:44:55 EST 2004
Skip Montanaro <skip at pobox.com> wrote in message news:<mailman.1.1079382673.742.python-list at python.org>...
> Fazer> I was wondering what's the best way of setting timeouts when
> Fazer> working with urllib2.
>
> Using 2.3+:
>
> >>> import socket
> >>> socket.setdefaulttimeout(3)
> >>> import urllib2
> >>> urllib2.urlopen("http://www.musi-cal.com/search?performers=Greg+Brown")
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/Users/skip/local/lib/python2.4/urllib2.py", line 130, in urlopen
> return _opener.open(url, data)
> File "/Users/skip/local/lib/python2.4/urllib2.py", line 338, in open
> response = self._open(req, data)
> File "/Users/skip/local/lib/python2.4/urllib2.py", line 356, in _open
> '_open', req)
> File "/Users/skip/local/lib/python2.4/urllib2.py", line 317, in _call_chain
> result = func(*args)
> File "/Users/skip/local/lib/python2.4/urllib2.py", line 988, in http_open
> return self.do_open(httplib.HTTPConnection, req)
> File "/Users/skip/local/lib/python2.4/urllib2.py", line 971, in do_open
> raise URLError(err)
> urllib2.URLError: <urlopen error timed out>
>
> Skip
Wow thanks! Any idea how I can accomplish this in Python 2.2 versions?
More information about the Python-list
mailing list