[Tutor] urllib2.urlopen(....., timeout=)
Ray Jones
crawlzone at gmail.com
Fri Sep 7 17:56:43 CEST 2012
On 09/07/2012 08:32 AM, Dave Angel wrote:
> On 09/07/2012 11:16 AM, Ray Jones wrote:
>> 2.7.3
>> According to the docs, urlopen has a timeout capability. But it says
>> that the timeout = '<object object>'
>>
>> I've tried integers as the timeout value, I've tried floats....it
>> doesn't complain about my values, but neither does it timeout. Can
>> anyone point me to the solution to getting the urlopen to timeout if the
>> target system isn't responding for some reason? What kind of objects is
>> it expecting?
>>
> I'm curious why the docstring says ... timeout = <object object>
> but have no clues for you.
>
> See http://docs.python.org/library/urllib2.html
>
> which says:
>
> The optional /timeout/ parameter specifies a timeout in seconds for
> blocking operations like the connection attempt (if not specified, the
> global default timeout setting will be used). This actually only works
> for HTTP, HTTPS and FTP connections.
>
> So I'd figure it wants an int, or maybe a float, as you've tried. is it
> possible that you're opening something which is neither HTTP, HTTPS nor
> FTP? What parameters exactly are you passing to urlopen ?
My urlopen string is the following:
urllib2.urlopen('http://%s:%s' % (ip, port), 'timeout = 2')
Aha! See my problem? I just noticed it. I've been treating the 'timeout'
portion as though I'm passing it as a command line parameter or
something. I removed the quotes and all is swell!
Y'all are awesome. Even when you don't have enough information to know
the solution you help me! :)
Ray
More information about the Tutor
mailing list