If no *timeout* is supplied, the global default timeout setting returned by :func:`getdefaulttimeout` is used.
getdefaulttimeout 函数在文档中已经有了非常明确地描述,你也可以点击这里查看:
Return the default timeout in seconds (float) for new socket objects. A value of None indicates that new socket objects have no timeout. When the socket module is first imported, the default is None.
Requests 库是基于 urllib3 的,其连接的发起是调用了 urlopen 方法。其超时时间默认是 urllib3 中的 DEFAULT_TIMEOUT 决定。
在 urllib3中:
而 _GLOBAL_DEFAULT_TIMEOUT 的值是由 python 标准库 socket.py 决定的,在 socket.py 的源码中可以看到:
getdefaulttimeout 函数在文档中已经有了非常明确地描述,你也可以点击这里查看:
也就是说当未指定超时时间时,默认的超时时间是 None,亦即连接永远不会超时。
对于 requests 的超时时间设置,在 requests 的文档中已经描述的非常清楚了,可以是一个浮点数或者一个元组,在此就不再赘述。