Python3 timeout error urllib.request.urlopen
I have a script, a witch is getting data from a site. I first wrote it in 2.7 python and his works. When I rewrite it in python3 I have a problem. In python2.7 which works great
for x in xrange(len(ll.string2)-1):
psR = urllib2.urlopen(ll.string2[x]).read()
nrL = Przystanek()
nrL.feed(psR)
self.BusExtData += nrL.string2
python3
for x in range(len(ll.string2)-1):
psR = urllib.request.urlopen(ll.string2[x],timeout=3000).read().decode('iso-8859-2')
nrL = Przystanek()
nrL.feed(psR)
self.BusExtData += nrL.string2
The top code generates a timeout error.
i = 0
while i<(len(ll.string2)-1):
try:
psR = urllib.request.urlopen(ll.string2[i],timeout=3000).read().decode('iso-8859-2')
nrL = Przystanek()
nrL.feed(psR)
self.BusExtData += nrL.string2
i=i+1
except:
print("Error")
i=i-1
pass
I avoid this uppercase problem. But I don't know why urllib2.urlopen doesn't make a timeout error. When I use urllib.request.urlopen I get this error message:
urllib.error.URLError: urlopen time error
or
urllib.error.URLError: urlopen time error [WinError 10060]
What is the difference between urlib2.urlopen and urllib.request.urlopen?
+3
source to share
No one has answered this question yet
Check out similar questions: