Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Client.__init__() got an unexpected keyword argument 'proxies' #1903

Closed
1 task done
gregpr07 opened this issue Nov 28, 2024 · 20 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@gregpr07
Copy link

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • 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

  1. pip install openai
  2. 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

@gregpr07 gregpr07 added the bug Something isn't working label Nov 28, 2024
@simonw
Copy link

simonw commented Nov 28, 2024

Same issue:

@dgellow
Copy link
Contributor

dgellow commented Nov 28, 2024

Thanks for the report, as mentioned by @simonw this is similar to #1902 and will be fixed by #1903. I will close this issue as duplicate.

Copy link
Contributor

stainless-app bot commented Nov 28, 2024

duplicate

@3218923350
Copy link

What is the solution now?

@3218923350
Copy link

I directly commented out the proxies in the constructor of SyncHttpxClientWrapper in openai/_base_client.py, and it works properly now.

@carmo-congree
Copy link

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: #1902 (comment)

@RobertCraigie
Copy link
Collaborator

Updating to the latest openai version will fix the issue.

@bsenftner
Copy link

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'

@RobertCraigie
Copy link
Collaborator

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__)'

@bsenftner
Copy link

bsenftner commented Dec 2, 2024

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.

@dgellow
Copy link
Contributor

dgellow commented Dec 2, 2024

@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

@bsenftner
Copy link

@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?

@bsenftner
Copy link

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.

@dgellow
Copy link
Contributor

dgellow commented Dec 2, 2024

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 :)

@ericzhou571
Copy link

Updating to the latest openai version 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?

httpx==0.25.2

@RobertCraigie
Copy link
Collaborator

@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__)

@goy-jin
Copy link

goy-jin commented Dec 5, 2024

我在 openai/_base_client.py 的 SyncHttpxClientWrapper 的构造函数中直接注释掉了代理,现在它现在可以正常工作了。

我没有找到这个

print(openai.version)
1.56.1

@redhatpeter
Copy link

redhatpeter commented Dec 5, 2024

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?

@dgellow
Copy link
Contributor

dgellow commented Dec 5, 2024

@redhatpeter A workaround is to pin the httpx version to 0.27.2, you can see it described here: #1902 (comment)

@vip2580
Copy link

vip2580 commented Dec 6, 2024

using autogen to create agents still having same issue
TypeError: Client.init() got an unexpected keyword argument 'proxies'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests