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

Nawaz picture Nawaz · Jul 22, 2013 · Viewed 90.1k times · Source

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?

Answer

ron rothman picture ron rothman · Jul 22, 2013

What is the default timeout that get uses?

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

What happens when you pass in a timeout value?

r = requests.get(
    'http://www.justdial.com',
    proxies={'http': '222.255.169.74:8080'},
    timeout=5
)