469,590 Members | 2,464 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,590 developers. It's quick & easy.

Timeouts with urllib2

Hello,

I was wondering what's the best way of setting timeouts when working with urllib2.

Thanks,
Jul 18 '05 #1
3 1827

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

Jul 18 '05 #2
Skip Montanaro <sk**@pobox.com> wrote in message news:<ma**********************************@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?
Jul 18 '05 #3
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")

...

Fazer> Any idea how I can accomplish this in Python 2.2 versions?

Google for timeoutsocket. There's also timeout_socket. Two different
implementations of timeouts.

Skip
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by bmiras | last post: by
1 post views Thread by Matthew Wilson | last post: by
2 posts views Thread by John F Dutcher | last post: by
5 posts views Thread by Pascal | last post: by
reply views Thread by jacob c. | last post: by
1 post views Thread by Ray Slakinski | last post: by
1 post views Thread by Alessandro Fachin | last post: by
1 post views Thread by Johny | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.