At my workplace we access internet through a proxy server IP entered in Preferences > Network > Connection > Manual Proxy configuration. where the Proxy IP is entered, I want to learn how to do that setup in python so for my internet based application .
-
I am looking for answer to this question for a very long time.Ciasto piekarz– Ciasto piekarz2015-05-11 08:34:32 +00:00Commented May 11, 2015 at 8:34
-
Are you on windows or a linux box?flazzarini– flazzarini2015-05-11 09:08:09 +00:00Commented May 11, 2015 at 9:08
-
Are you trying to use a Python application to connect to the internet through the proxy, or are you trying to use Python to setup your proxy connection for another application? Those are two wildly different things.Wayne Werner– Wayne Werner2015-05-11 14:29:52 +00:00Commented May 11, 2015 at 14:29
-
I am trying to use a Python application to connect to the internet through the proxy.Ciasto piekarz– Ciasto piekarz2015-05-11 15:11:52 +00:00Commented May 11, 2015 at 15:11
-
Does this SO post help? stackoverflow.com/questions/1450132/proxy-with-urllib2mlctrez– mlctrez2015-05-11 15:37:20 +00:00Commented May 11, 2015 at 15:37
|
Show 2 more comments
1 Answer
You can set http_proxy environment variable or you can set this information accordly with lib used. As example, requests libs:
import requests
proxies = {
"http": "http://10.10.1.10:3128",
"https": "http://10.10.1.10:1080",
}
requests.get("http://example.org", proxies=proxies)
UPDATE
A tool that can help in corporate environments is cntlm http://cntlm.sourceforge.net/ , an NTLM / NTLM Session Response / NTLMv2 authenticating HTTP proxy.
Once configured, you only have to point to your proxy in http://localhost:3128.
2 Comments
Ciasto piekarz
it gives me <Response [407]> i.e. HTTP Error 407 Proxy authentication required , which means I have to pass my username and password as argument somewhere to do a get request !
Ciasto piekarz
later I added username and password like mentioend here and it worked. docs.python-requests.org/en/latest/user/advanced/#proxies