By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

configure 'time out' time for urllib

P: n/a
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()

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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()


Jul 18 '05 #2

P: n/a
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()


Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.