-
Notifications
You must be signed in to change notification settings - Fork 392
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
Added proxy support for Python3 #90
base: master
Are you sure you want to change the base?
Conversation
Why just Py3? The urllib module in Py2 also supports proxies, and it already does by setting the corresponding environment variable. I'd rather not clutter the API with even more parameters, TBH. |
That was just laziness I guess. And to your point, I think my use case is somewhat an edge case: only proxy requests to Google, but do not proxy requests to other domains. I'm fine closing this and just using my implementation when I need it if that's your preference. |
Mhm, that's an interesting use case. May I ask a bit more? :) |
It's just for situations where for speed reasons I don't want to use different proxies for different tasks. |
Very interesting. When will it be committed? |
Adding proxy support is definitely a great enhancement to this project. As a Windows user I don't think I can just set a proxy as easily as on Linux. Can't see why it hasn't been merged so far. |
Setting the environment variable works the same in Windows as in Linux. I haven't merged it because I want to keep all functionality working in all versions of Python. |
Setting the environment variable also works, but if you need to change(the proxy) in the middle of the program the urlopen doesn't refresh the environment variable value. So if you do: import os
from urllib.request import urlopen
#List of proxies
proxies = [
'191.96.71.118:3128',
'186.219.96.47:54570',
]
for p in proxies:
os.environ['http_proxy'] = 'http://' + p
url = 'http://ipecho.net/plain'
print(f'Trying {p}')
res = urlopen(url)
print('Used ', res) The result is: Trying 191.96.71.118:3128
Used 191.96.71.118
Trying 186.219.96.47:54570
Used 191.96.71.118 So i think is a valid feature. |
What's New
This PR implements proxy support for Python3 usage of the library. Now you can very easily use a proxy by passing a proxy
url
to theproxy
argument for thesearch
function: