Office365-rest-python-client: Fehler in "acquire_token_for_user"

Erstellt am 4. Dez. 2019  ·  11Kommentare  ·  Quelle: vgrem/Office365-REST-Python-Client

Hallo,

Ich habe versucht, mich mit dem Office365-REST-Python-Client mit meinem Intranet-Sharepoint-Portal zu verbinden, aber es schlägt fehl, wenn apply_token_for_user() aus der AuthenticationContext-Klasse aufgerufen wird:

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

löst folgenden Fehler aus:

AttributeError: 'NoneType'-Objekt hat kein Attribut 'text'

Grüße,
Markierung

question

Hilfreichster Kommentar

Bei mir funktioniert es auch. Die URL kann auch etwas wie " https://mycompany.sharepoint.com/sites/AnotherSite " oder " https://mycompany.sharepoint.com/sites/AnotherSite/Subsite " sein.

Versuchen Sie es stattdessen mit diesem Code:

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)

Alle 11 Kommentare

Ich habe genau das gleiche Problem

Das gleiche ist gerade aufgetaucht, kann nicht mehr auf den Sharepoint zugreifen.

Ich habe das gleiche Problem und kann nicht auf den Unternehmens-Sharepoint zugreifen. In anderer Ausgabe (#76 , am 5. August 2018) zeigt die nächste Lösung (die bei mir noch nicht funktioniert hat):

_Behoben. Das Problem war die Verwendung eines Firmenbenutzers, bei dem eine Prüfung nur per Browser zwischen Azure Active Directory und internem Active Direcotry durchgeführt wird. Für das Batch-Skript habe ich einen Benutzer in der Cloud AAD angelegt._

Eigentlich habe ich meinen Benutzer im AAD, aber ich kann immer noch nicht darauf zugreifen :( irgendeine Lösung/ein Hinweis?

Mein Code funktioniert:
userName = 'meinBenutzername'
passWord = 'meinpasswort'
ctx_auth.acquire_token_for_user(username=userName, password=passWord)

Bei mir funktioniert es auch. Die URL kann auch etwas wie " https://mycompany.sharepoint.com/sites/AnotherSite " oder " https://mycompany.sharepoint.com/sites/AnotherSite/Subsite " sein.

Versuchen Sie es stattdessen mit diesem Code:

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)

Dieses Problem sollte mit PullRequest #168 behoben werden
Sie sollten nun eine spezifischere Fehlermeldung sehen.
Wir haben diesen spezifischen Fehler immer dann erhalten, wenn die Authentifizierung fehlgeschlagen ist.

Hinweis: Sie müssen auf die neueste Version 2.1.6-1 aktualisieren

Hallo Mark, @fpinab ,

nur ein kleines Update, da du erwähnt hast:

Eigentlich habe ich meinen Benutzer im AAD

Ich glaube, Sie beziehen sich auf Office 365 Single Sign-On für das ADFS- Szenario, dieser Flow wurde nicht unterstützt und das ist wahrscheinlich der Grund, warum der angegebene Fehler aufgetreten ist.

Die gute Nachricht, die Unterstützung für die SAML-basierte Verbundauthentifizierung mit SharePoint Online wurde in Version 2.1.7 , was bedeutet, dass die Authentifizierung mit Active Directory-Benutzerkonten jetzt wie erwartet funktioniert.

Voraussetzungen

Es wird davon ausgegangen, dass die Multi-Faktor-Authentifizierung für einen Benutzer deaktiviert ist

Anmerkungen

Da die neue Version noch nicht für PyPi freigegeben wurde, muss sie derzeit stattdessen von GitHub installiert werden, wie folgt:

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

Danke schön,
Wadim

@vgrem
Ich habe auf die neue Version aktualisiert, um zu versuchen, das ADFS-Szenario zu unterstützen. aber ich funktioniert immer noch nicht.
unten ist das Codebeispiel:

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)

unten ist das Protokoll:

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

@Simplici , bist du v2.1.8 oder höher auf deiner Seite verwendet wird?

Andernfalls könnten Sie auf das gleiche Problem stoßen, das hier gemeldet

@vgrem ich habe 2.1.7.post1 verwendet.

Ich aktualisiere auf die neueste Version 2.1.9, das Ergebnis ist das gleiche.

mein Kollege hat etwas modifiziert und dann funktioniert es: https://github.com/vgrem/Office365-REST-Python-Client/issues/210.

@vgrem Ich habe das gleiche Problem. Der folgende Code gibt den Fehler "Beim Abrufen von Authentifizierungscookies von https://company.sharepoint.com/_vti_bin/idcrl.svc ist ein Fehler aufgetreten" zurück.

Ich habe auch 2.1.7.post1 installiert, aber ich habe keinen Administratorzugriff, um die Multifaktor-Authentifizierung zu überprüfen.

aus office365.runtime.auth.authentication_context importieren AuthenticationContext
aus office365.sharepoint.client_context importieren ClientContext
aus office365.sharepoint.file importieren Datei

url = ' https://company.sharepoint.com '
Benutzername = ' [email protected] '
Passwort = 'xxx'

ctx_auth = AuthenticationContext(url)

if ctx_auth.acquire_token_for_user(Benutzername, Passwort):
ctx = ClientContext(url, ctx_auth)
web = ctx.web
...

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen