urllib2 and timeout question

G

Gerard C Blais

I'm trying to get a page from a slow server. and i'm timing out.

I've tried

socket.setdefaulttimeout9300), and

urllib2.socket.setdefaulttimeout(300), and

urllib2.socket.setdefauttimeout(300.0),

but all seem to give up after 20 seconds.

What's the best (or a good) way to increase the timeout?

(the url works fine, but slowly, when pasted into a browser)

Thanks,

Gerry

============

Code below:

import time
import urllib2
import socket

starting_time = time.clock()

socket.setdefaulttimeout(300)
print "timeout set"

lat = 38.836971
lon = -77.378228

starting_width = 20
ending_width = 0.01

index = 0
width = starting_width

while width > ending_width:
width *= 0.3
index += 1
url = "http://tiger.census.gov/cgi-bin/mapper/map.gif?lat=" +
str(lat) + \
"&lon=" + str(lon) + \
"&wid=" + str(width) + \
"&iht=719&iwd=843&&on=majroads&mlat=" + str(lat) + \
"&mlon=" + str(lon) + \
"&msym=redpin&mlabel=SMM&conf=mapnew.con"

url_start_time = time.clock()
print round(starting_time,0), url

try:
fd = urllib2.urlopen(url)
except:
print time.clock(), "timed out"
 
S

Skip Montanaro

Gerard> Code below:

Order might be important (though hopefully not). Can you give this a try?

import time
import socket
socket.setdefaulttimeout(300)
import urllib2

...

Skip
 
G

Gerard C Blais

Thanks for the suggestion:

My program now starts like this:


import time
import socket
socket.setdefaulttimeout(300)
import urllib2
import httplib


import urlparse, gzip
from StringIO import StringIO


and it hasn't helped.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top