configure 'time out' time for urllib

Discussion in 'Python' started by Andreas Dahl, Feb 26, 2004.

  1. Andreas Dahl

    Andreas Dahl Guest

    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()
    Andreas Dahl, Feb 26, 2004
    #1
    1. Advertising

  2. Andreas Dahl

    wes weston Guest

    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()
    >
    wes weston, Feb 26, 2004
    #2
    1. Advertising

  3. Andreas Dahl

    wes weston Guest

    Andreas,
    Follow the link in Pieter's reply. It explains that the method
    changes the timeout for ALL connections. You won't need to recode
    in sockets. Thanks Pieter.
    wes

    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()
    >
    wes weston, Feb 26, 2004
    #3
    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:
    436
  2. Pieter Claerhout

    RE: configure 'time out' time for urllib

    Pieter Claerhout, Feb 26, 2004, in forum: Python
    Replies:
    0
    Views:
    439
    Pieter Claerhout
    Feb 26, 2004
  3. Abandoned

    configure urllib.urlretrieve timeout

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

    Asynchronous urllib (urllib+asyncore)?

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

Share This Page