TypeError: Client.init() got an unexpected keyword argument ‘proxies’
现象:
在使用openai包时出现错误 openai.OpenAI(**client_params, **sync_specific)
报错信息:
Traceback (most recent call last):
File "/Users/greg/Documents/Work/browser-use/browser-use/examples/try.py", line 45, in <module>
llm = get_llm(args.provider)
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/greg/Documents/Work/browser-use/browser-use/examples/try.py", line 28, in get_llm
return ChatOpenAI(model='gpt-4o', temperature=0.0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/greg/Documents/Work/browser-use/browser-use/.venv/lib/python3.11/site-packages/langchain_core/load/serializable.py", line 125, in __init__
super().__init__(*args, **kwargs)
File "/Users/greg/Documents/Work/browser-use/browser-use/.venv/lib/python3.11/site-packages/pydantic/main.py", line 214, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/greg/Documents/Work/browser-use/browser-use/.venv/lib/python3.11/site-packages/langchain_openai/chat_models/base.py", line 551, in validate_environment
self.root_client = openai.OpenAI(**client_params, **sync_specific) # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/greg/Documents/Work/browser-use/browser-use/.venv/lib/python3.11/site-packages/openai/_client.py", line 123, in __init__
super().__init__(
File "/Users/greg/Documents/Work/browser-use/browser-use/.venv/lib/python3.11/site-packages/openai/_base_client.py", line 857, in __init__
self._client = http_client or SyncHttpxClientWrapper(
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/greg/Documents/Work/browser-use/browser-use/.venv/lib/python3.11/site-packages/openai/_base_client.py", line 755, in __init__
super().__init__(**kwargs)
TypeError: Client.__init__() got an unexpected keyword argument 'proxies'
Python版本
python 3.8
openai版本
openai 1.9.0
原因
安装openai包时没指定httpx包版本,httpx包在11.28进行更新,安装了httpx 0.28.0 版本的包导致报错
解决方法
1、指定httpx包版本为0.27.2
pip install httpx==0.27.2
2、安装openai包>=1.55.3版本
说明:在2024.11.28httpx更新新版本后出现异常,在2024.11.29 openai发布新版本修复,参考:1.55.3版本更新说明
pip install openai>=1.55.3