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

Passing proxies to a websocket #415

Open
johnraysimpson opened this issue Oct 23, 2024 · 3 comments
Open

Passing proxies to a websocket #415

johnraysimpson opened this issue Oct 23, 2024 · 3 comments
Labels
question Ask for help or clarification

Comments

@johnraysimpson
Copy link

The question

I just wanted clarity on using proxies with a websocket specifically, I'm assuming that if I set up a session with certain proxies, then use the ws_connect method then the proxies will be utilised for that request? E.g.

from curl_cffi import requests

session = requests.Session(proxies=some_proxy_dict)
ws = session.ws_connect(some_ws_url)  # the proxies are passed from the session to the websocket connection
@johnraysimpson johnraysimpson added the question Ask for help or clarification label Oct 23, 2024
@johnraysimpson
Copy link
Author

johnraysimpson commented Oct 25, 2024

I've had a dig around and got it to work, I'm not sure if it's a bug or not but someone might be able to figure that out, but using
Session(proxies={"http": "http://some_proxy", "https": "https://some_proxy"})
doesn't appear to make websocket connections through that proxy. My work around at the moment is:
Session(proxy=some_proxy_str)

(was able to test as I have access to a few proxy providers and know of a websocket url that only works with some - using the first method made connections no matter the proxies whereas the second method failed on the proxies I expected to fail)

@perklet
Copy link
Collaborator

perklet commented Oct 25, 2024

Thanks for posting your findings back.

I think we should add something like proxies={"ws": "http://some_proxy", "wss": "https://some_proxy"} for consistency. Let's keep this open until it's resolved.

@johnraysimpson
Copy link
Author

Ah right, makes more sense now, would it be nice to have a routine that converts the {"http": "http://some_proxy", "https": "https://some_proxy"} in a session to proxies={"ws": "http://some_proxy", "wss": "https://some_proxy"} when connecting to a websocket through Session? Only use case is when needing to make normal requests and websocket connections with the same IP, I think that would be quite elegant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Ask for help or clarification
Projects
None yet
Development

No branches or pull requests

2 participants