requests中timeout问题

requests.get(url,headers=headers,timeout=130)
我调用一个接口,设置了timeout时间为130,然后调用时,感觉他们的接口一直停在那里,没有响应,没有输出,也没有报错。过了130秒之后,也没有timeout错误。直到4分钟之后,接口正常输出结果。
请问有人遇到过这个情况么?
为什么timeout没作用?

阅读 7.9k
1 个回答

timeout is not a time limit on the entire response download; rather, an exception is raised if the server has not issued a response for timeout seconds (more precisely, if no bytes have been received on the underlying socket for timeout seconds). If no timeout is specified explicitly, requests do not time out.

官网 上如是说

简单来说就是 timeout 并不是整个下载响应的时间限制,而是如果服务器在 timeout 秒内没有应答,将会引发一个异常。timeout能设置到130我猜大概是你网速不好吧。过程我觉得是130s内收到应答,后来的时间用来下载数据.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进