urllib2 timeout issue

J

Jérôme

Hi all.

I'm having troubles with urllib2 timeout.

See the following script :

----------------------------
import urllib2
result = urllib2.urlopen("http://dumdgdfgdgmyurl.com/")
print result.readline()
----------------------------

If run on my Debian Wheezy computer, or on my Debian Squeeze server,
the answer is instantaneous :

[...]
urllib2.URLError: <urlopen error [Errno -2] Name or service not known>

When run on my Raspberry Pi with Raspian Wheezy, the answer is
identical but it takes 10 seconds.

I tried

result = urllib2.urlopen("http://dumdgdfgdgmyurl.com/", timeout=5)

but I get the same results : instantaneous on Debian, 10 secondes on
RPi.

I also added this, as suggested on some StackOverflow pages :

import socket
socket.setdefaulttimeout(5)

and it didn't make any difference.

In both cases, Python version is "Python 2.7.3".

Am I missing something ?

Thanks.
 
P

Piet van Oostrum

Jérôme said:
Hi all.

I'm having troubles with urllib2 timeout.

See the following script :

----------------------------
import urllib2
result = urllib2.urlopen("http://dumdgdfgdgmyurl.com/")
print result.readline()
----------------------------

If run on my Debian Wheezy computer, or on my Debian Squeeze server,
the answer is instantaneous :

[...]
urllib2.URLError: <urlopen error [Errno -2] Name or service not known>

When run on my Raspberry Pi with Raspian Wheezy, the answer is
identical but it takes 10 seconds.

I tried

result = urllib2.urlopen("http://dumdgdfgdgmyurl.com/", timeout=5)

but I get the same results : instantaneous on Debian, 10 secondes on
RPi.

I also added this, as suggested on some StackOverflow pages :

import socket
socket.setdefaulttimeout(5)

and it didn't make any difference.

In both cases, Python version is "Python 2.7.3".

Am I missing something ?

I would guess the difference to be caused by DNS. Maybe the DNS configuration on the RPi is not optimal.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top