RE: configure 'time out' time for urllib

Discussion in 'Python' started by Pieter Claerhout, Feb 26, 2004.

  1. 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 |
    | www.creo.com

    IMAGINE CREATE BELIEVE(tm)

    -----Original Message-----
    From: python-list-bounces+pieter.claerhout=
    [mailto:python-list-bounces+pieter.claerhout=] On Behalf
    Of wes weston
    Sent: 26 February 2004 16:39
    To:
    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
     
    Pieter Claerhout, Feb 26, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HS1
    Replies:
    0
    Views:
    470
  2. Andreas Dahl

    configure 'time out' time for urllib

    Andreas Dahl, Feb 26, 2004, in forum: Python
    Replies:
    2
    Views:
    3,800
    wes weston
    Feb 26, 2004
  3. Abandoned

    configure urllib.urlretrieve timeout

    Abandoned, Oct 7, 2007, in forum: Python
    Replies:
    1
    Views:
    626
    Steve Holden
    Oct 7, 2007
  4. Jonathan Gardner

    Asynchronous urllib (urllib+asyncore)?

    Jonathan Gardner, Feb 26, 2008, in forum: Python
    Replies:
    1
    Views:
    478
    Terry Jones
    Feb 27, 2008
  5. Chris McDonald
    Replies:
    0
    Views:
    302
    Chris McDonald
    Nov 1, 2010
Loading...

Share This Page