urllib2 timeout issue

Jérôme jerome at jolimont.fr
Fri Oct 18 07:19:07 EDT 2013


Thu, 17 Oct 2013 15:55:06 +0200
Ervin Hegedüs a écrit:

> Has your router/modem any HTTP proxy feature? If yes, maybe the
> proxy gives the late answer.

I don't think so. I didn't find anything like this in the config.
 
> Anyway, if you don't have proxy, and the DNS error cames from
> local system, you can try to decrease it via resolv.conf:
> 
> nameserver 1.2.3.4
> options timeout:2
> 
> It's just an idea... but maybe...
>
> Note that the 2 seconds for DNS timeout in resolv.conf may sound crazy,
> because the _real_slow_ DNS answers will be timeouted for any
> application - just take a test with it.

Yes. See my former message :

> I found this on my server's config:
> 
> options timeout:1
> 
> I added it to /etc/resolv.conf on my Pi and PC and I get a much shorter
> timeout, yet still longer than the value I enter, longer than I expect, and
> longer that what I have on other machines (instantaneous).
> 
> But at least I see something happening.

This was not a really satisfying solution.

Besides, I'd rather solve the issue in the software, so that it works
anywhere without the user having to play with DNS config and all. Even if the
discussion on my DNS config is interesting, my question was about
urllib2.urlopen() timeout. I thought the timeout parameter was meant to
escape those long delays. Apparently, it is not.

According to this SO topic:

http://stackoverflow.com/questions/14127115/python-2-6-urlib2-timeout-issue

urllib2 does not do that.

Some workarounds are suggested.

Perhaps the simplest solution for me would be to create my own urlopen()
function, that would call urllib2's, and add a timeout in there.

I don't get the logic, here. I would call it a bug in urllib2, but I won't
allow myself to do that until I've understood the explanation on SO.

-- 
Jérôme



More information about the Python-list mailing list