You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

InfluxDB 2.7.5调用find_buckets()报TypeError: <lambda>存在意外参数'key_key_password'

解决InfluxDB Python客户端调用buckets.find_buckets()时的key_key_password错误

问题重现

使用InfluxDB 2.7.5,通过官方示例代码调用buckets.find_buckets()时触发错误:

TypeError: <lambda>() got an unexpected keyword argument 'key_key_password'

用户代码:

import time
from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS

url = "你的InfluxDB地址"
token = "你的Token"
org = "你的组织"
bucket = "你的Bucket"

client = InfluxDBClient(url=url, token=token, org=org)
write_api = client.write_api(write_options=SYNCHRONOUS)
query_api = client.query_api()
delete_api = client.delete_api()
buckets = client.buckets_api()

print("buckets", buckets.find_buckets())

for value in range(5):
  point = (
    Point("measurement1")
    .tag("id", "1")
    .field("field1", value)
  )
  write_api.write(bucket=bucket, org=org, record=point)
  time.sleep(1) # separate points by 1 second

write_api.close()

完整错误栈:

Traceback (most recent call last):
  File "/influxManager.py", line 21, in <module>
    print("buckets", buckets.find_buckets())
  File "/opt/anaconda3/lib/python3.9/site-packages/influxdb_client/client/bucket_api.py", line 119, in find_buckets
    return self._buckets_service.get_buckets(**kwargs)
  File "/opt/anaconda3/lib/python3.9/site-packages/influxdb_client/service/buckets_service.py", line 558, in get_buckets
    (data) = self.get_buckets_with_http_info(**kwargs)  # noqa: E501
  File "/opt/anaconda3/lib/python3.9/site-packages/influxdb_client/service/buckets_service.py", line 586, in get_buckets_with_http_info
    return self.api_client.call_api(
  File "/opt/anaconda3/lib/python3.9/site-packages/influxdb_client/_sync/api_client.py", line 343, in call_api
    return self.__call_api(resource_path, method,
  File "/opt/anaconda3/lib/python3.9/site-packages/influxdb_client/_sync/api_client.py", line 173, in __call_api
    response_data = self.request(
  File "/opt/anaconda3/lib/python3.9/site-packages/influxdb_client/_sync/api_client.py", line 365, in request
    return self.rest_client.GET(url,
  File "/opt/anaconda3/lib/python3.9/site-packages/influxdb_client/_sync/rest.py", line 268, in GET
    return self.request("GET", url,
  File "/opt/anaconda3/lib/python3.9/site-packages/influxdb_client/_sync/rest.py", line 235, in request
    r = self.pool_manager.request(method, url,
  File "/opt/anaconda3/lib/python3.9/site-packages/urllib3/request.py", line 66, in request
    return self.request_encode_url(method, url, fields=fields,
  File "/opt/anaconda3/lib/python3.9/site-packages/urllib3/request.py", line 89, in request_encode_url
    return self.urlopen(method, url, **extra_kw)
  File "/opt/anaconda3/lib/python3.9/site-packages/urllib3/poolmanager.py", line 313, in urlopen
    conn = self.connection_from_host(u.host, port=u.port, scheme=u.scheme)
  File "/opt/anaconda3/lib/python3.9/site-packages/urllib3/poolmanager.py", line 229, in connection_from_host
    return self.connection_from_context(request_context)
  File "/opt/anaconda3/lib/python3.9/site-packages/urllib3/poolmanager.py", line 240, in connection_from_context
    pool_key = pool_key_constructor(request_context)
  File "/opt/anaconda3/lib/python3.9/site-packages/urllib3/poolmanager.py", line 105, in _default_key_normalizer
    return key_class(**context)
TypeError: <lambda>() got an unexpected keyword argument 'key_key_password'

解决方案

这个错误是urllib3版本与influxdb_client版本不兼容导致的:urllib3新版本新增了key_key_password参数,但旧版influxdb_client的连接池键构造lambda函数未适配该参数。

解决方法二选一:

  • 降级urllib3到兼容版本:
    pip install urllib3==1.26.16
    
  • 升级influxdb_client到最新兼容版本:
    pip install --upgrade influxdb-client
    

验证

调整版本后重新运行代码,buckets.find_buckets()可正常返回桶列表,写入数据的逻辑也能正常执行。

内容的提问来源于stack exchange,提问作者Gray

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 18:14:53