configure 'time out' time for urllib

Pieter Claerhout Pieter.Claerhout at Creo.com
Thu Feb 26 10:56:43 EST 2004


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 http://www.timo-tasi.org/python/timeoutsocket.py, which works as
follows:

    import timeoutsocket
    timeoutsocket.setDefaultSocketTimeout(10)

Cheers,


pieter

Creo
pieter claerhout | product support prinergy | tel: +32 2 352 2511 |
pieter.claerhout at creo.com | www.creo.com

IMAGINE CREATE BELIEVE(tm)

-----Original Message-----
From: python-list-bounces+pieter.claerhout=creo.com at python.org
[mailto:python-list-bounces+pieter.claerhout=creo.com at python.org] On Behalf
Of wes weston
Sent: 26 February 2004 16:39
To: python-list at python.org
Subject: Re: configure 'time out' time for urllib

Andreas,
    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("http://www.ncbi.nlm.nih.gov/SNP/snp_ref.cgi?%s" %
> 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()
> 

-- 
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list