Python请求无法连接到Squid代理

时间:2014-02-20 11:18:34

标签: python http proxy python-requests squid

我有一个需要身份验证的squid代理。在squid.conf我正在使用:

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

从此我可以预期身份验证方法为http digest

这是我的python代码:

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 )

我收到此错误:

407 Proxy Authentication Required

我也尝试过验证:

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

和:

http://user:password@ip

没有运气......

有人可以帮忙吗?

由于

1 个答案:

答案 0 :(得分:2)

HTTPDigestAuth未通过代理对您进行身份验证,它会通过网站对您进行身份验证。目前,请求没有任何内置方式将Digest Auth与代理and there are no plans to add built-in support一起使用。

您必须使用代理(通过将您的凭据放在代理URL中,例如proxies={'http': 'http://user:password@domain.com'}),或者为Proxy Digest Auth编写您自己的身份验证处理程序。