class HTTPBasicAndProxyAuth:
def __init__(self, basic_up, proxy_up):
# basic_up is a tuple with username, password
self.basic_auth = HTTPBasicAuth(*basic_up)
# proxy_up is a tuple with proxy username, password
self.proxy_auth = HTTPProxyAuth(*proxy_up)
def __call__(self, r):
# this emulates what basicauth and proxyauth do in their __call__()
# first add r.headers['Authorization']
r = self.basic_auth(r)
# then add r.headers['Proxy-Authorization']
r = self.proxy_auth(r)
# and return the request, as the auth object should do
return r
不幸的是,
HTTPProxyAuth
是HTTPBasicAuth
的子代,并重写其行为(请参见requests/auth.py
)。但是,您可以通过创建一个实现这两个行为的新类,将这两个必需的头添加到请求中:
这并不漂亮,但您可以在代理和受限制的页面url中提供单独的BasicAuth凭据。
例如:
对于基本身份验证,可以使用python的Httplib2模块。下面给出了一个例子。有关详细信息,请查看this
我不认为Httplib2提供代理支持。检查link-
相关问题 更多 >
编程相关推荐