4

ここでHTTPProxyAuthの使用例を見つけましたhttps://stackoverflow.com/a/8862633

しかし、HTTPProxyAuth と HTTPBasicAuth IE の両方での使用例を期待しています。サーバー、ユーザー名、パスワードをプロキシ経由で渡し、ユーザー名とパスワードを Web ページに渡す必要があります...

前もって感謝します。

リチャード

4

3 に答える 3

1

基本認証の場合、Python の Httplib2 モジュールを使用できます。以下に例を示します。詳細については、これを確認してください

>>>import httplib2

>>>h = httplib2.Http(".cache")

>>>h.add_credentials('name', 'password')

>>>resp, content = h.request("https://example.org/chap/2", 
"PUT", body="This is text", 
headers={'content-type':'text/plain'} )

Httplib2 がプロキシ サポートを提供するとは思わない。リンクを確認してください-

于 2012-06-08T12:48:59.360 に答える
0

残念ながら、HTTPProxyAuthは の子でHTTPBasicAuthあり、その動作をオーバーライドします ( を参照してくださいrequests/auth.py)。

ただし、両方の動作を実装する新しいクラスを作成することで、必要な両方のヘッダーをリクエストに追加できます。

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
于 2014-04-01T06:50:40.440 に答える
0

きれいではありませんが、プロキシと制限されたページ URL の両方で個別の BasicAuth 資格情報を提供できます。

例えば:

proxies = {
 "http": "http://myproxyusername:mysecret@webproxy:8080/",
 "https": "http://myproxyusername:mysecret@webproxy:8080/",
}

r = requests.get("http://mysiteloginname:myothersecret@mysite.com", proxies=proxies)
于 2015-02-09T15:06:29.220 に答える