In requests library, how can I avoid “HttpConnectionPool is full, discarding connection” warning?

后端 未结 2 449
长发绾君心
长发绾君心 2021-02-07 06:47

I\'m using python requests library with sessions:

def _get_session(self):
    if not self.session:
        self.session = requests.Session()
    return self.sess         


        
2条回答
  •  故里飘歌
    2021-02-07 07:13

    I'd like to clarify some stuff here.

    What max_poolsize argument does is limit the number of TCP connections that can be stored in the connection pool simultaneously. Normally, when you want to execute a HTTP requests, requests will try to take a TCP connection from its connection pool. If there are no available connections, requests will create a new TCP connection, and when it is done making a HTTP request, it will try to put it back in the pool (it will not remember whether the connection was taken from the connection pool or not).

    The Full exception being raised in requests code is just an example of a common Python pattern usually paraphrased as it is easier to ask for forgiveness than for permission. It has nothing with dropping TCP connections.

提交回复
热议问题