Office365-rest-python-client: Acquisition_token_for_userのエラー

作成日 2019年12月04日  ·  11コメント  ·  ソース: vgrem/Office365-REST-Python-Client

こんにちは、

Office365-REST-Python-Clientを使用してイントラネットSharepointポータルに接続しようとしましたが、AuthenticationContextクラスからacquire_token_for_user()を呼び出すと失敗します。

url = " https://mycompany.sharepoint.com "
ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user( "my_username"、 "my_password")

次のエラーが発生します。

AttributeError: 'NoneType'オブジェクトに属性 'text'がありません

よろしく、
マーク

question

最も参考になるコメント

それは私にとってもうまくいきます。 URLは、「 https://mycompany.sharepoint.com/sites/AnotherSite 」または「 https://mycompany.sharepoint.com/sites/AnotherSite/Subsite 」のようにすることもでき

代わりに、次のコードを試してください。

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.runtime.client_request import ClientRequest
from office365.runtime.utilities.request_options import RequestOptions

user_credentials = {
    'username' : '[email protected]',
    'password' : 'my_password'
}

site_url = "https://mycompany.sharepoint.com/"

ctx_auth = AuthenticationContext(site_url)
if ctx_auth.acquire_token_for_user(user_credentials['username'], user_credentials['password']):
  request = ClientRequest(ctx_auth)
  options = RequestOptions("{0}/_api/web/lists".format(site_url))
  options.set_header('Accept', 'application/json')
  options.set_header('Content-Type', 'application/json')
  data = request.execute_request_direct(options)
  s = json.loads(data.content)

全てのコメント11件

私はまったく同じ問題を抱えています

同じように、これはポップアップしたばかりで、SharePointにアクセスできなくなりました。

同じ問題があり、エンタープライズSharePointにアクセスできません。 他の号(#76、2018年8月5日)では、次の解決策を示しています(まだ私には機能しませんでした):

_解決しました。 問題は、Azure ActiveDirectoryと内部のActiveDirecotryの間で、ブラウザーを介してのみチェックが実行される会社のユーザーの使用でした。 バッチスクリプトでは、クラウドAADにユーザーを作成しました。_

実際、私はAADにユーザーがいますが、それでもアクセスできません:(解決策/手がかりはありますか?

私のコードは機能します:
userName = 'myusername'
passWord = 'mypassword'
ctx_auth.acquire_token_for_user(username = userName、password = passWord)

それは私にとってもうまくいきます。 URLは、「 https://mycompany.sharepoint.com/sites/AnotherSite 」または「 https://mycompany.sharepoint.com/sites/AnotherSite/Subsite 」のようにすることもでき

代わりに、次のコードを試してください。

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.runtime.client_request import ClientRequest
from office365.runtime.utilities.request_options import RequestOptions

user_credentials = {
    'username' : '[email protected]',
    'password' : 'my_password'
}

site_url = "https://mycompany.sharepoint.com/"

ctx_auth = AuthenticationContext(site_url)
if ctx_auth.acquire_token_for_user(user_credentials['username'], user_credentials['password']):
  request = ClientRequest(ctx_auth)
  options = RequestOptions("{0}/_api/web/lists".format(site_url))
  options.set_header('Accept', 'application/json')
  options.set_header('Content-Type', 'application/json')
  data = request.execute_request_direct(options)
  s = json.loads(data.content)

この問題はPullRequest#168で修正する必要があります
より具体的なエラーメッセージが表示されます。
認証が失敗するたびに、この特定のエラーが発生しました。

注:最新バージョン2.1.6-1にアップグレードする必要があります

ちょっとマーク、 @ KasperSvendsen@fpinab

あなたが言及したので、ほんの小さな更新:

実際、私はAADにユーザーがいます

ADFSシナリオの

幸いなことに、SharePoint OnlineでのSAMLベースのフェデレーション認証のサポートがバージョン2.1.7で導入されました。つまり、ActiveDirectoryユーザーアカウントでの認証が期待どおりに機能するはずです。

前提条件

ユーザーの多要素認証が無効になっていることを前提としています

ノート

新しいバージョンはまだPyPiにリリースされていないため、現時点では、次のように、代わりにGitHubからインストールする必要があります。

pip install git + https://github.com/vgrem/Office365-REST-Python-Client.git

乾杯、
ヴァディム

@vgrem
ADFSシナリオをサポートするために、新しいバージョンに更新しました。 しかし、私はまだ動作しません。
以下はコード例です。

from office365.runtime.auth.authentication_context import AuthenticationContext
account = "[email protected]"
password = "example"
url = "https://example.sharepoint.com/sites/base-dok-testing"

ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user(account, password)

以下はログです:

16/Jun/2020 10:18:15] DEBUG [none] [office365.runtime.auth.saml_token_provider.SamlTokenProvider.acquire_token:acquire_token:45] acquire_token called
[16/Jun/2020 10:18:15] DEBUG [none] [office365.runtime.auth.saml_token_provider.SamlTokenProvider.acquire_token:acquire_token:48] Acquiring Access Token..
[16/Jun/2020 10:18:15] DEBUG [none] [urllib3.connectionpool:_new_conn:955] Starting new HTTPS connection (1): login.microsoftonline.com:443
[16/Jun/2020 10:18:16] DEBUG [none] [urllib3.connectionpool:_make_request:428] https://login.microsoftonline.com:443 "POST /GetUserRealm.srf HTTP/1.1" 200 1448
[16/Jun/2020 10:18:16] DEBUG [none] [urllib3.connectionpool:_new_conn:955] Starting new HTTPS connection (1): fs.kerialis.fr:443
[16/Jun/2020 10:18:20] DEBUG [none] [urllib3.connectionpool:_make_request:428] https://fs.kerialis.fr:443 "POST /adfs/services/trust/2005/usernamemixed HTTP/1.1" 200 6542
[16/Jun/2020 10:18:20] DEBUG [none] [urllib3.connectionpool:_new_conn:955] Starting new HTTPS connection (1): login.microsoftonline.com:443
[16/Jun/2020 10:18:21] DEBUG [none] [urllib3.connectionpool:_make_request:428] https://login.microsoftonline.com:443 "POST /rst2.srf HTTP/1.1" 200 3499
[16/Jun/2020 10:18:21] DEBUG [none] [urllib3.connectionpool:_new_conn:955] Starting new HTTPS connection (1): kerialisfr.sharepoint.com:443
[16/Jun/2020 10:18:21] DEBUG [none] [urllib3.connectionpool:_make_request:428] https://kerialisfr.sharepoint.com:443 "HEAD /sites/base-dok-testing/_vti_bin/idcrl.svc HTTP/1.1" 401 0
[16/Jun/2020 10:18:21] ERROR [none] [office365.runtime.auth.saml_token_provider.SamlTokenProvider.acquire_authentication_cookie:acquire_authentication_cookie:208] An error occurred while retrieving auth cookies from https://kerialisfr.sharepoint.com/sites/base-dok-testing/_vti_bin/idcrl.svc

@Simpliciv2.1.8以降のバージョンがあなたの側で利用されていることを確信していますか?

そうしないと、ここで報告されたのと同じ問題に遭遇する可能性があり

@vgrem私は

最新リリース2.1.9にアップデートしても、結果は同じです。

私の同僚がいくつかの変更を加えた後、それは機能します: https

@vgrem同じ問題があります。 次のコードは、「 https://company.sharepoint.com/_vti_bin/idcrl.svcから認証Cookieを取得中にエラーが発生しました」というエラーを返し

2.1.7.post1もインストールしていますが、多要素認証を確認するための管理者アクセス権がありません。

office365.runtime.auth.authentication_contextからimportAuthenticationContext
office365.sharepoint.client_contextからimportClientContext
office365.sharepoint.fileからインポートファイル

url = ' https://company.sharepoint.com '
ユーザー名='[email protected] '
パスワード= 'xxx'

ctx_auth = AuthenticationContext(url)

ctx_auth.acquire_token_for_user(username、password)の場合:
ctx = ClientContext(url、ctx_auth)
web = ctx.web
..。

このページは役に立ちましたか?
0 / 5 - 0 評価