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

Basic SOCKS proxy support #195

Closed
wants to merge 2 commits into from
Closed

Basic SOCKS proxy support #195

wants to merge 2 commits into from

Conversation

mufeedali
Copy link
Member

Fixes #192

Based on Lollypop's handling of the same. Unfortunately, this isn't exactly ideal. As discussed in #115 (comment) previously, py-googletrans and httpx do not properly support proxies. But for now, this should hopefully work.

if host != "" and port != 0:
# Reset proxy env vars
environ["all_proxy"] = ""
environ["ALL_PROXY"] = ""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to do this because something kept reading it from the environment variable and did not allow the app to work. But from my experimentation using NetHogs, the proxy seems to work just fine, so it should be okay.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not work here (timeout on search). Looks like settings variable is mandatory.

Tried but your right, something manually tries to understand proxy env :(

Copy link
Member Author

@mufeedali mufeedali Sep 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see :(

Too bad. Well... proper proxy support and a bunch of other large changes will be coming eventually, so maybe we will have to put this off until then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, converting to draft and will experiment again soon if possible. But unfortunately... it works for me now. So I don't know how to proceed 😅 .

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will try to debug

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be awesome! Thanks!

@mufeedali
Copy link
Member Author

@bellegarde-c if you find time to, could you test to see if this works as expected in a real-world test? (I could only test with the experimental setup you suggested 😅)

@mufeedali mufeedali marked this pull request as draft September 7, 2021 09:40
@bellegarde-c
Copy link

Ok, tried this code:

import httpx
import socks
import socket

socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 8080)
socket.socket = socks.socksocket

URL = 'http://ifconfig.me/ip'

with httpx.Client() as client:
    resp = client.get(URL)
    print(resp.text)

But fails with httpx.ConnectError: [Errno 97] Address family not supported by protocol

So until httpx socks support is out encode/httpx#203 and gtrans add support for it, we can't do more IMO.

@bellegarde-c
Copy link

Hmm, or it's because IPV6 is disabled on my laptop.

@mufeedali
Copy link
Member Author

Ok, tried this code (...)

Interesting... This works for me until I enable the proxy in GNOME settings. When I do that, httpx tries to use the environment variable and fails irrespective of it is socks4 or just socks.

@rigens
Copy link

rigens commented Nov 26, 2021

There is a fairly stable 3rd party SOCKS implementation: httpx-socks

@mufeedali
Copy link
Member Author

There is a fairly stable 3rd party SOCKS implementation: httpx-socks

We use httpx through py-googletrans for Google Translate. So we can't implement this.

@mufeedali
Copy link
Member Author

Closing this because transition to libsoup should solve this and is being done in #235 .

@mufeedali mufeedali closed this Feb 2, 2022
@rafaelmardojai rafaelmardojai deleted the proxy-basic branch September 18, 2022 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Does not work behind a socks proxy server
3 participants