Python proxy connection

I am trying to connect to urls from python. I tried: urllib2, urlib3 and queries. This is the same problem that I encounter in all cases. As soon as I get the answer, I think that all three will work fine.

The problem is with the proxy server. I entered our proxy information, but I do not get any joy. I get 407 codes and error messages, such as: HTTP Error 407: Proxy Authentication Required (Forefront TMG requires authorization to complete the request. Access to the web proxy filter is denied.)

However, I can connect using another application that passes through a proxy server, such as git. When I run git config --get htpp.proxy , it returns the same values ​​and format that I enter in Python, namely

 http://username: password@proxy :8080 

Example code in queries

 import requests proxy = {"http": "http://username: password@proxy :8080"} url = 'http://example.org' r = requests.get(url, proxies=proxy) print r.status_code 

thank you for your time

+4
source share
3 answers

I solved the problem by installing CNTLM. After setting up and configuring, I set HTTP_PROXY etc.

+1
source

In the request module, proxy authentication is performed as shown:

 import requests proxies = {'http':'http://xxxx', 'https':'https://xxxx'} auth = requests.auth.HTTPProxyAuth('username', 'password') r = requests.get('http://www.example.com', proxies = proxies, auth = auth) print r.status_code, r.reason 
+3
source

You can use HTTP_PROXY in python to connect to your proxy server. You can find more information about this link.

http://www.wkoorts.com/wkblog/2008/10/27/python-proxy-client-connections-requiring-authentication-using-urllib2-proxyhandler/

The above link shows an example using urllib2 . In fact, I used this a while ago to connect to two servers at the same time. Hope this helps you.

0
source

Source: https://habr.com/ru/post/1482284/


All Articles