简体   繁体   中英

Python Requests cannot connect to Squid Proxy

I have a squid proxy that requires authentication. In squid.conf I am using:

auth_param digest program /usr/lib64/squid/digest_pw_auth -c /etc/squid/passwords

auth_param digest realm proxy

acl authenticated proxy_auth REQUIRED

http_access allow authenticated

From this I can expect the authentication method to be http digest .

Here is my python code:

from requests.auth import HTTPDigestAuth

auth = HTTPDigestAuth("user", "pass")

r = requests.get( "http://www.google.com", allow_redirects=True, headers=Configuration.HEADERS, proxies=proxy_list(), auth=auth )

I am receiving this error:

407 Proxy Authentication Required

I have also tried authenticating with:

auth = HTTPProxyAuth('user', 'password')

and:

http://user:password@ip

With no luck...

Can anybody help?

Thanks

HTTPDigestAuth doesn't authenticate you with the proxy, it authenticates you with the website. Right now Requests doesn't have any built-in way of using Digest Auth with a proxy, and there are no plans to add built-in support .

You'll have to either use with the proxy (by putting your credentials in the proxy URL, eg proxies={'http': 'http://user:password@domain.com'} ), or write your own authentication handler for Proxy Digest Auth.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM