zoukankan      html  css  js  c++  java
  • python 第三方库 网络 requests

    requests - timeout

    为防止服务器响应缓慢,导致客服端处理异常,requests请求大多设置 timeout 参数。Requests中timeout 不设置默认值。

    Timeout 类型:

    • 连接超时指的是客户端实现到远端服务器端口的连接时request 所等待的时间。连接超时一般设为比 3 的倍数略大的一个数值,因为 TCP 数据包重传窗口的默认大小是 3。
    • 读取超时指的客户端已经连接上服务器并且发送了request后,客户端等待服务器发送请求的时间。(一般指的是服务器发送第一个字节之前的时间)。

    客户端timeout 秒内从套接字上必须接收到第一个字节的数据, 否则抛出超时异常。

    timeout 设置单一的值,将会用作 connectread 二者的 timeout。

    requests.get('https://github.com', timeout=5)
    

    如果要分别制定,就需要传入一个元组。

    requests.get('https://github.com', timeout=(3.05, 27))
    

    如果需要让 request 永远等待,则传入一个 None 作为 timeout 的值。

    requests.get('https://github.com', timeout=None)
    
  • 相关阅读:
    JavaScript
    monkeyrunner总结
    repo简介
    android4.4 settings 中控制卡1 卡2都振动
    卡1卡2设置不同的默认铃声
    获取布局 ActionBar
    android Settings 解析
    设置应用中出现NFC服务,去掉
    判断当前网络显示运营商
    设置中默认铃声 通知 闹钟等
  • 原文地址:https://www.cnblogs.com/hiyang/p/12805227.html
Copyright © 2011-2022 走看看