Python 使用Twisted的代理用户名/密码
我试图使用Twisted的类连接到代理服务器并发出HTTP请求,但是服务器需要用户名和密码。是否可以使用ProxyAgent向服务器指定这些凭据Python 使用Twisted的代理用户名/密码,python,proxy,twisted,Python,Proxy,Twisted,我试图使用Twisted的类连接到代理服务器并发出HTTP请求,但是服务器需要用户名和密码。是否可以使用ProxyAgent向服务器指定这些凭据 endpoint = TCP4ClientEndpoint(reactor, host, port) agent = ProxyAgent(endpoint) # Maybe need to pass auth credentials in the header here? body = agent.request("GET", path) 解决问
endpoint = TCP4ClientEndpoint(reactor, host, port)
agent = ProxyAgent(endpoint)
# Maybe need to pass auth credentials in the header here?
body = agent.request("GET", path)
解决问题后,必须在标题中设置代理授权字段:
endpoint = TCP4ClientEndpoint(reactor, host, port)
agent = ProxyAgent(endpoint)
headers = {}
auth = base64.b64encode("%s:%s" % (username, password))
headers["Proxy-Authorization"] = ["Basic " + auth.strip()]
body = agent.request("GET", path, Headers(headers))