1
urllib.requests
には、複数の認証ハンドラを渡すことができるオープナを構築できます。あなたはPythonリクエストで同じことをすることができますか?複数の認証ハンドラを追加してコールを要求する
リクエストdocサイトのサンプルは、一度に1つの認証ハンドラを渡すだけですが、2つを渡す必要があります。これは可能ですか?
これはどのように構文/ドキュメントを提供できますか?ここで
は、私がurllib.requestsパッケージでそれを行うだろうかです:
password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
# Add the username and password.
# If we knew the realm, we could use it instead of None.
top_level_url = "http://example.com/foo/"
password_mgr.add_password(None, top_level_url, username, password)
handler1 = urllib.request.HTTPBasicAuthHandler(password_mgr)
handler2 = urllib.request.HTTPDigestAuthHandler(password_mgr)
# create "opener" (OpenerDirector instance)
opener = urllib.request.build_opener([handler1, handler2])
# use the opener to fetch a URL
opener.open(a_url)
# Install the opener.
# Now all calls to urllib.request.urlopen use our opener.
urllib.request.install_opener(opener)
あなたは何について話していますか? HTTP認証ヘッダ? 'Authorization:Basic footer'のように? – Arount
@ArountリクエストにHttpBasicAuthとHTTPDisgestAuthの両方を渡したいと思います。 urllib.requestsでは、オープナーが複数のハンドラーオブジェクトを処理できるように、get/post操作でBasic認証が発生した場合は基本ハンドラーを使用し、ダイジェストするとダイジェストハンドラーが使用されます。私が作業しているサイトとサブサイトには、セキュリティが混在しています。 –
あなたは '要求'で翻訳したい 'urllib 'を使って作業コードを貼り付けてください。 – Arount