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

查看:1506
本文介绍了为什么不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.justdial.com",
    proxies = {'http': '222.255.169.74:8080'},
)

print(r.ok)

可能的原因是什么S)?任何补救措施?什么是 get 使用的默认超时值?

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

推荐答案


获取使用的默认超时值是多少?

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
)

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

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