Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't requests.get() return? What is the default timeout that requests.get() uses?

In my script, requests.get never returns:

import requests  print ("requesting..")  # This call never returns! r = requests.get(     "http://www.some-site.com",     proxies = {'http': '222.255.169.74:8080'}, )  print(r.ok) 

What could be the possible reason(s)? Any remedy? What is the default timeout that get uses?

like image 925
Nawaz Avatar asked Jul 22 '13 07:07

Nawaz


People also ask

What is the default timeout for requests in Python?

The default timeout is None , which means it'll wait (hang) until the connection is closed.

What is request timeout?

The HyperText Transfer Protocol (HTTP) 408 Request Timeout response status code means that the server would like to shut down this unused connection. It is sent on an idle connection by some servers, even without any previous request by the client.

What does requests get () do?

The get() method sends a GET request to the specified url.

Does Python have a timeout?

Since Python 3.5, there's a handy and recommended run() API in subprocess module, which has built-in timeout support.


1 Answers

What is the default timeout that get uses?

The default timeout is None, which means it'll wait (hang) until the connection is closed.

Just specify a timeout value, like this:

r = requests.get(     'http://www.justdial.com',     proxies={'http': '222.255.169.74:8080'},     timeout=5 ) 
like image 199
ron rothman Avatar answered Sep 21 '22 22:09

ron rothman