Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: configure 'time out' time for urllib

Thread Tools

RE: configure 'time out' time for urllib

Pieter Claerhout
Posts: n/a
I think you will have to configure the default timeout for the socket
module. If you have Python 2.3, it works as follows:

import socket
socket.setdefaulttimeout(10) # timeout in seconds

For older versions of Python, you have to rely on the timeoutsocket module
from, which works as

import timeoutsocket



pieter claerhout | product support prinergy | tel: +32 2 352 2511 | Removed) |


-----Original Message-----
From: python-list-bounces+pieter.claerhout=(E-Mail Removed)
[mailtoython-list-bounces+pieter.claerhout=(E-Mail Removed)] On Behalf
Of wes weston
Sent: 26 February 2004 16:39
To: (E-Mail Removed)
Subject: Re: configure 'time out' time for urllib

I had a similar problem and coded in two tries; could be 3,4 etc.
I couldn't find a way to set the timeout.

Andreas Dahl wrote:
> Hi,
> I use urllib to retrieve data via HTTP. Unfortunately my program crashes
> after a while (after some loops) because the connection timed out.
> raise socket.error, msg
> IOError: [Errno socket error] (60, 'Connection timed out')
> I am not so familiar with python, but is there a possibility to
> configure the 'waiting time'? Or how can I handle such an event? To skip
> that query and go to the next one would also work.
> Many thanks in advance, Andreas
> code:
> params = urllib.urlencode({'rs': rs})
> try:
> file =
> urllib.urlopen("" %
> params)
> except IOError, message: # file open failed
> print >> sys.stderr, "File could not be opend:", message
> sys.exit(1)
> data = file.readlines() # array with html-doc-content
> file.close()


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
2to3 urllib.URLopener -> urllib.request.URLopener Chris McDonald Python 0 11-01-2010 11:23 AM
Asynchronous urllib (urllib+asyncore)? Jonathan Gardner Python 1 02-27-2008 12:51 AM
configure urllib.urlretrieve timeout Abandoned Python 1 10-07-2007 12:07 PM
different between configure libraries and configure JDKs HS1 Java 0 11-18-2004 03:40 AM
configure 'time out' time for urllib Andreas Dahl Python 2 02-26-2004 06:52 PM