Python请求,警告:urllib3.connectionpool:连接池已满 [英] Python Requests, warning: urllib3.connectionpool:Connection pool is full
问题描述
我正在python 3中使用requests库,尽管我已尽力而为,但我无法收到以下警告消失:
I'm using the requests library in python 3 and despite my best efforts I can't get the following warning to disappear:
警告:requests.packages.urllib3.connectionpool:连接池已满,正在丢弃连接:myorganization.zendesk.com
WARNING:requests.packages.urllib3.connectionpool:Connection pool is full, discarding connection: myorganization.zendesk.com
我正在多线程环境中使用请求,以将json文件同时发送和发布到单个主机,绝对没有子域.在当前设置中,我仅使用20个线程.
I'm using requests in a multithreaded environment to get and post json files concurrently to a single host, definitely no subdomains. In this current set up I'm using just 20 threads.
我尝试使用Session
来获取重用连接的请求,从而解决了该问题,但这没有用.这是我的类构造函数中的代码:
I attempted to use a Session
in order to get requests to reuse connections and thus get rid of the problem, but it hasn't worked. This is the code in my class constructor:
self.session = requests.Session()
adapter = requests.adapters.HTTPAdapter(
pool_connections=100, pool_maxsize=100)
self.session.mount('http://', adapter)
self.session.headers.update({'Connection':'Keep-Alive'})
self.session.auth = (self._user+"/token", self._token)
根据此处的建议我不需要增加考虑到我正在使用的线程数来考虑池化连接,但是尽管如此,即使将其提高100,我仍然会收到此警告.
According to advice from here I shouldn't need to increase the pooled connections by that much considering the number of threads I'm using, but despite this I get this warning even when raising by 100.
这使我认为连接根本没有被重用,或者由于某种原因而创建了太多连接.我已经更新了请求,所以它是最新版本.
This makes me think that connections are not being reused at all, or if they are, too many are being created for some reason. I've updated requests, so it is the most up to date version.
有人对我如何摆脱这个想法有任何想法吗?我正在调试一些代码,我认为这是某些请求未正确发出的原因.
Does anyone have any ideas how I can get rid of this? I'm debugging some code and I think this is the blame for some requests not being made correctly.
相关:
推荐答案
由于zendesk通过https进行通信,因此您只需要将适配器安装到https协议即可,即
Since zendesk communicates over https, you just need to mount the adapter to the https protocol, i.e.
self.session.mount('https://', adapter)
这篇关于Python请求,警告:urllib3.connectionpool:连接池已满的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!