我可以为Python的“请求"更改连接池大小吗?模块? [英] Can I change the connection pool size for Python's "requests" module?
本文介绍了我可以为Python的“请求"更改连接池大小吗?模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(也许我错了,这个错误是什么意思.这表明我的CLIENT上的连接池已满吗?还是SERVER上的连接池已满,这是我的客户端得到的错误?)
(edit: Perhaps I am wrong in what this error means. Is this indicating that the connection pool at my CLIENT is full? or a connection pool at the SERVER is full and this is the error my client is being given?)
我正在尝试使用python threading
和requests
模块同时发出大量http
请求.我在日志中看到此错误:
I am attempting to make a large number of http
requests concurrently using the python threading
and requests
module. I am seeing this error in logs:
WARNING:requests.packages.urllib3.connectionpool:HttpConnectionPool is full, discarding connection:
如何为请求增加连接池的大小?
What can I do to increase the size of the connection pool for requests?
推荐答案
这应该可以解决问题:
import requests
sess = requests.Session()
adapter = requests.adapters.HTTPAdapter(pool_connections=100, pool_maxsize=100)
sess.mount('http://', adapter)
resp = sess.get("/mypage")
这篇关于我可以为Python的“请求"更改连接池大小吗?模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文