2017-07-26 30 views
0

私は、ユーザ名とパスワードが必要なPythonでURLを開こうとしています。エラーが消えたが、他はその場所に登場した後AbstractBasicAuthHandlerは以下のスキームをサポートしていません: 'Negotiate' [Python]

import urllib.request 
url = 'http://example.com' 
username = 'user' 
password = 'password' 
passman = urllib.request.HTTPPasswordMgrWithDefaultRealm() 
passman.add_password(None, url, username, password) 
auth_handler = urllib.request.HTTPBasicAuthHandler(passman) 
opener = urllib.request.build_opener(auth_handler) 
urllib.request.install_opener(opener) 

hereurllib.error.HTTPError: HTTP Error 401: Unauthorized 

私はこのように見えるように私のスクリプトをモッドチュートリアル次のとおりです。 は、初めに、このエラー示すがありました

ValueError: AbstractBasicAuthHandler does not support the following scheme: 'Negotiate' 

何が問題なのでしょうか?

+0

requestsに私は、私はかなり理解してないと思います。私はすでに7行目に書いてあります。 – Zombistic

答えて

0

スイッチ

Basic Authentication

Many web services that require authentication accept HTTP Basic Auth. This is the simplest kind, and Requests supports it straight out of the box.

Making requests with HTTP Basic Auth is very simple:

import requests 
from requests.auth import HTTPBasicAuth 
requests.get('http://example.com', auth=HTTPBasicAuth('user', 'pass')) 
<Response [200]> 

In fact, HTTP Basic Auth is so common that Requests provides a handy shorthand for using it:

requests.get('https://api.github.com/user', auth=('user', 'pass')) 
<Response [200]> 

Providing the credentials in a tuple like this is exactly the same as the HTTPBasicAuth example above.

+0

私はそれを使いました。 'TypeError:add_password()missing 1必要な位置引数: 'realm''したがって、add_passwordの最後に閉じ括弧を追加しました。まだ動作していない(さらに別のエラーが表示されます)が、今回はURLに問題がある可能性が非常に高いです。 – Zombistic

+1

とてもうまく動作します。ありがとう、私はそれを感謝します。 – Zombistic

関連する問題