为什么 requests.get() 不返回?requests.get() 使用的默认超时是多少? [英] Why doesn't requests.get() return? What is the default timeout that requests.get() uses?

查看:31
本文介绍了为什么 requests.get() 不返回?requests.get() 使用的默认超时是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的脚本中,requests.get 从不返回:

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)

可能的原因是什么?有什么补救办法吗?get 使用的默认超时是多少?

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

推荐答案

get 使用的默认超时时间是多少?

What is the default timeout that get uses?

默认超时为None,这意味着它将等待(挂起)直到连接关闭.

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
)

这篇关于为什么 requests.get() 不返回?requests.get() 使用的默认超时是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆