我可以更改 Python 的“请求"的连接池大小吗?模块? [英] Can I change the connection pool size for Python's "requests" module?
本文介绍了我可以更改 Python 的“请求"的连接池大小吗?模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(也许我在这个错误的含义上错了.这是否表明我的客户端的连接池已满?或者服务器上的连接池已满,这是我的客户端出现的错误?)
(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.adapters
session = requests.Session()
adapter = requests.adapters.HTTPAdapter(pool_connections=100, pool_maxsize=100)
session.mount('http://', adapter)
response = session.get("/mypage")
这篇关于我可以更改 Python 的“请求"的连接池大小吗?模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文