473,499 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1914

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4437
by: bmiras | last post by:
I've got a problem using urllib2 to get a web page. I'm going through a proxy using user/password authentification and i'm trying to get a page asking for a HTTP authentification. And I'm using...
1
3938
by: Matthew Wilson | last post by:
I am writing a script to check on my router's external IP address. My ISP refreshes my IP very often and I use dyndns for the hostname for my computer. My Netgear mr814 router has a webserver that...
2
6069
by: John F Dutcher | last post by:
Can anyone comment on why the code shown in the Python error is in some way incorrect...or is there a problem with Python on my hoster's site ?? The highlites don't seem to show here...but line...
5
7374
by: Pascal | last post by:
Hello, I want to acces my OWA (Outlook Web Acces - http Exchange interface) server with urllib2 but, when I try, I've always a 401 http error. Can someone help me (and us)? Thanks. ...
0
2631
by: jacob c. | last post by:
When I request a URL using urllib2, it appears that urllib2 always makes the request using HTTP 1.0, and not HTTP 1.1. I'm trying to use the "If-None-Match"/"ETag" HTTP headers to conserve...
0
1845
by: Gil Tal | last post by:
Hi, I use urllib2 to download a redirected url and I get an exception from the bowels of urllib2. It seems that urllib2 implements some super sophisticated self check and tries to control the...
1
3347
by: Ray Slakinski | last post by:
Hello, I have defined a function to set an opener for urllib2, this opener defines any proxy and http authentication that is required. If the proxy has authencation itself and requests an...
1
5732
by: Alessandro Fachin | last post by:
I write this simply code that should give me the access to private page with htaccess using a proxy, i don't known because it's wrong... import urllib,urllib2 #input url...
1
1065
by: Johny | last post by:
In my script I started using urllib2 to connect to a list of servers.It works well but only until a server from the list is not available.Then if it is down , there is a timeout and my script...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.