Client.__init__() got an unexpected keyword argument 'proxies'
🚨 错误信息
self._client = http_client or SyncHttpxClientWrapper(
TypeError: Client.__init__() got an unexpected keyword argument 'proxies'
🤖 AI解决方案
报错分析报告
1. 错误翻译
原文:TypeError: Client.__init__() got an unexpected keyword argument 'proxies'
译文:TypeError: Client.__init__() 收到了一个意外的关键字参数 'proxies'
2. 原因分析
根本原因:SyncHttpxClientWrapper 或底层的 httpx Client 类的 __init__ 方法不支持名为 proxies 的参数。
错误位置:
- 在创建
SyncHttpxClientWrapper实例时,传递了proxies参数 - 可能是通过
http_client参数传递,或在包装器初始化时直接传递 - 目标客户端类不支持该参数,导致
TypeError
3. 解决方案
方案一:检查客户端配置方式(推荐)
# 修复前的问题代码
self._client = http_client or SyncHttpxClientWrapper(
proxies=proxies, # ❌ 这里传入了不支持的参数
timeout=30,
verify=False
)
# 修复后的代码
# 方式1:如果不需要代理,移除proxies参数
self._client = http_client or SyncHttpxClientWrapper(
timeout=30,
verify=False
)
# 方式2:如果需要设置代理,查看客户端文档正确配置方式
# 可能需要通过其他方式配置代理,如环境变量或不同的参数名
self._client = http_client or SyncHttpxClientWrapper(
# 查看 SyncHttpxClientWrapper 的实际可用参数
# 可能正确的参数是 'http_client' 或 'transport'
timeout=30,
verify=False
)
方案二:使用 httpx 原生客户端
import httpx
# 如果需要代理,使用 httpx 原生的方式
self._client = httpx.Client(
proxies=proxies, # ✅ httpx.Client 支持 proxies 参数
timeout=30,
verify=False
)
4. ️ 预防措施
最佳实践建议
️ 推荐工具
help(SyncHttpxClientWrapper.__init__) 或 SyncHttpxClientWrapper.__init__.__annotations__ 查看可用参数