【问题标题】:Python Requests cannot connect to Squid ProxyPython 请求无法连接到 Squid 代理
【发布时间】:2014-02-20 11:18:33
【问题描述】:

我有一个需要身份验证的 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

没有运气......

有人可以帮忙吗?

谢谢

【问题讨论】:

  • 什么是proxies_list()
  • 只是一个生成代理列表字典的函数

标签: python http proxy python-requests squid


【解决方案1】:

HTTPDigestAuth 不会通过代理对您进行身份验证,而是通过网站对您进行身份验证。目前,Requests 没有任何内置方式使用带有代理的 Digest Auth,and there are no plans to add built-in support

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

【讨论】:

  • 我认为可能是这种情况,遗憾的是,使用 user:password 不适用于摘要身份验证,因此我不得不恢复我的 squid 设置以使用有效的基本 http 身份验证。我将来可能会编写一个身份验证处理程序。感谢您的意见。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-06
  • 2022-12-03
  • 2015-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-09
相关资源
最近更新 更多