gpt4 book ai didi

python - 为什么 requests.get() 不返回? requests.get() 使用的默认超时是多少?

转载 作者:IT老高 更新时间:2023-10-28 21:33:29 26 4
gpt4 key购买 nike

在我的脚本中,requests.get 永远不会返回:

import requests

print ("requesting..")

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

print(r.ok)

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

最佳答案

What is the default timeout that get uses?

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

只需 specify a timeout value ,像这样:

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

关于python - 为什么 requests.get() 不返回? requests.get() 使用的默认超时是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17782142/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com