python - 在线程中更改 Python 的 "requests"模块的连接池大小

标签 python multithreading python-requests request connection-pooling

(编辑:也许我对这个错误的含义有误。这是否表明我的 CLIENT 上的连接池已满?或者 SERVER 上的连接池已满,这是我的客户端出现的错误?)

我正在尝试使用 python threadingrequests 模块同时发出大量 http 请求。我在日志中看到此错误:

WARNING:requests.packages.urllib3.connectionpool:HttpConnectionPool is full, discarding connection:

如何增加请求的连接池大小?

最佳答案

这应该可以解决问题:

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 - 在线程中更改 Python 的 "requests"模块的连接池大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18466079/

相关文章:

python - 运行export_inference_graph.py会给出类型差异错误

c++ - 鼠标抖动/消息处理循环

c# - 执行阻塞方法时返回数据

python - 我想提取成员(member)链接

python - Curl 到 Python 请求 - Json

python - 使用 re.match 过滤字符串列表时失败

python - Django ATOMIC_REQUESTS 不工作

python - Jupyter 在 Homebrew Python 更新后报告 "bad interpreter"

java - 每秒用多线程更新 JLabel

python - Beautiful Soup - 剥离 HTML 标签时返回奇怪的字符