TypeError: Client.__init__() got an unexpected keyword argument 'proxies'
Confirm this is an issue with the Python library and not an underlying OpenAI API
- [X] This is an issue with the Python library
Describe the bug
SyncHttpxClientWrapper has hard coded proxies but it no longer exists in httpx 0.28
To Reproduce
pip install openai- the bug appears when calling
openai.OpenAI(**client_params, **sync_specific)
Code snippets
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'
OS
macOS
Python version
Python v3.11.4
Library version
openai 1.55.2
Same issue:
- #1902
Thanks for the report, as mentioned by @simonw this is similar to #1902 and will be fixed by https://github.com/openai/openai-python/issues/1903. I will close this issue as duplicate.
duplicate
What is the solution now?
I directly commented out the proxies in the constructor of SyncHttpxClientWrapper in openai/_base_client.py, and it works properly now.
I directly commented out the proxies in the constructor of SyncHttpxClientWrapper in openai/_base_client.py, and it works properly now.
@3218923350 , this worked for me: https://github.com/openai/openai-python/issues/1902#issuecomment-2506402338
Updating to the latest openai version will fix the issue.
Is this supposed to be fixed? I'm still seeing the 'proxies' issue when trying to update a container at AWS. I've updated to OpenAI 1.55.3, and my code does not use Httpx at all. I'm using the Async client.
client = AsyncOpenAI( api_key=get_settings().OPENAI_API_KEY, )
File "/home/app/venv/lib/python3.9/site-packages/openai/_client.py", line 337, in __init__
super().__init__(
File "/home/app/venv/lib/python3.9/site-packages/openai/_base_client.py", line 1428, in __init__
self._client = http_client or AsyncHttpxClientWrapper(
File "/home/app/venv/lib/python3.9/site-packages/openai/_base_client.py", line 1325, in __init__
super().__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'proxies'
Hey @bsenftner are you sure you're on the latest version? You can verify by running this command
python -c 'import openai; print(openai.__version__)'
Yes I am on the latest version. I log the OpenAI version via "RUN pip3 show openai" during container build, as well as
import openai
log.info(f"LOOOOOOK: openai.__version__ {openai.__version__}")
from openai import AsyncOpenAI
#
client = AsyncOpenAI(
api_key=get_settings().OPENAI_API_KEY,
)
when my app starts up and both confirm version 1.55.3.
@bsenftner Could you try to pin httpx to 0.27.2? That wouldn't explain why it doesn't work in your environment but would unblock you
@dgellow I'm starting to think my pipeline may have some additional issue. I tried your suggestion of pinning httpx to 0.27.2 yesterday, and still saw the issue. Since that time my AWS specialist has been double checking things, so I'm trying the pinning of httpx to 0.27.2 again and will report back.
No one else is seeing this, still, I guess?
Looks like the pinning is working now. My local container builds have been working the entire time, so I suspect I need to examine my build & deploy pipeline at AWS. If it's only me, then it's only my issue.
Based on the symptoms you're describing I suspect your docker image is using an old cache (i.e one of the layer comes from a cache instead of being rebuilt). But yes, so far you have been the only one reporting that issue. Glad you were able to make the pinning work :)
Updating to the latest
openaiversion will fix the issue.
We have already updated OpenAI using pip install openai==1.56.0. However, with httpx==0.28.0, the issue (TypeError: Client.__init__() got an unexpected keyword argument 'proxies') still persists.
We resolved it by downgrading httpx to version 0.27.x. To isolate the environment, we created a new Conda environment and reinstalled both httpx and openai using the command:
pip install openai "httpx[socks]"
This installed the latest OpenAI version (1.56.0) as expected, but it still installed httpx==0.28.0 despite the requirements.lock file in your repository specifying httpx==0.25.2. Could you clarify why pip's dependency resolution process doesn’t respect the version specified in requirements.lock?
https://github.com/openai/openai-python/blob/534d6c58f6c07d219ca74dd336eaca59d48d0ada/requirements.lock#L29
@ericzhou571 the requirements.lock file is only for internal usage, we wouldn't want to impose direct pins for all our dependencies as that would cause so many version conflicts.
Are you sure you're using the latest version? What does running this output?
import openai
print(openai.__version__)
我在 openai/_base_client.py 的 SyncHttpxClientWrapper 的构造函数中直接注释掉了代理,现在它现在可以正常工作了。
我没有找到这个
print(openai.version) 1.56.1
Has this issue been fixed? still happening to me. python -c 'import openai; print(openai.version)' 1.56.2 TypeError: Client.init() got an unexpected keyword argument 'proxies' is there any workaround solution?
@redhatpeter A workaround is to pin the httpx version to 0.27.2, you can see it described here: https://github.com/openai/openai-python/issues/1902#issuecomment-2506402338
using autogen to create agents still having same issue TypeError: Client.init() got an unexpected keyword argument 'proxies'