1、下面两种方法是相同的,requests都会默认建立10个连接数上限制是10的连接池
import requests
#方法1
s = requests.Session()
s.get('https://www.baidu.com')
#方法2
requests.get('https://www.baidu.com')
2、其中涉及到的几个参数
pool_connections=DEFAULT_POOLSIZE,
pool_maxsize=DEFAULT_POOLSIZE,
max_retries=DEFAULT_RETRIES,
pool_block=DEFAULT_POOLBLOCK
"""
:param pool_connections: The number of urllib3 connection pools to cache.
:param pool_maxsize: The maximum number of connections to save in the pool.
:param max_retries: The maximum number of retries each connection
should attempt. Note, this applies only to failed DNS lookups, socket
connections and connection timeouts, never to requests where data has
made it to the server. By default, Requests does not retry failed
connections. If you need granular control over the conditions under
which we retry a request, import urllib3's ``Retry`` class and pass
that instead.
:param pool_block: Whether the connection pool should block for connections.
"""
#默认值
DEFAULT_POOLBLOCK = False
DEFAULT_POOLSIZE = 10
DEFAULT_RETRIES = 0
(1)一个host对应一个连接池,默认一个连接池同时支持10个链接,当超过限制时,由pool_block参数决定是否阻塞等待。
(2)也可以通Sessio的mount函数和HTTPAdapter修改默认配置。
3、参考: