3

TwistedのProxyAgentクラスを使用してプロキシサーバーに接続し、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)
4

1 に答える 1

4

問題を理解するには、Proxy-Authorizationフィールドをヘッダーに設定する必要があります。

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))
于 2012-06-22T20:41:47.500 に答える