Office365-rest-python-client: Acquire_token_for_user 中的错误

创建于 2019-12-04  ·  11评论  ·  资料来源: vgrem/Office365-REST-Python-Client

你好,

我尝试使用 Office365-REST-Python-Client 连接到我的 Intranet 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条评论

我有完全相同的问题

同样,这只是弹出,无法再访问共享点。

我有同样的问题,无法访问企业共享点。 在其他问题(#76,2018 年 8 月 5 日)中显示了下一个解决方案(对我来说还没有用):

_解决。 问题是使用公司用户,仅通过浏览器在 Azure Active Directory 和内部 Active Direcotry 之间执行检查。 对于批处理脚本,我已经在云中创建了一个用户 AAD._

实际上,我在 AAD 中有我的用户,但我仍然无法访问 :( 任何解决方案/线索?

我的代码有效:
用户名 = '我的用户名'
密码 = '我的密码'
ctx_auth.acquire_token_for_user(用户名=用户名,密码=密码)

它也适用于我。 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方案的

好消息是, 2.1.7版本中引入了对基于 SAML 的 SharePoint Online 联合身份验证的支持,这意味着如果我们现在按预期工作,则使用 Active Directory 用户帐户进行身份验证。

先决条件

假设用户的多因素身份验证已禁用

笔记

因为新版本尚未发布的PyPI,它需要从GitHub安装在代替的那一刻,就像这样:

pip 安装 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

@Simplici ,您是否肯定v2.1.8或更高版本在您身边使用?

否则,您可能会遇到与此处报告的相同的问题。

@vgrem我使用的是 2.1.7.post1。

我更新到最新版本 2.1.9,结果是一样的。

我的同事做了一些修改,然后它就可以工作了: https :

@vgrem我有同样的问题。 以下代码返回错误“从https://company.sharepoint.com/_vti_bin/idcrl.svc检索身份验证 cookie 时发生错误”

我也安装了 2.1.7.post1,但我没有管理员权限来检查多因素身份验证。

从 office365.runtime.auth.authentication_context 导入 AuthenticationContext
从 office365.sharepoint.client_context 导入 ClientContext
从 office365.sharepoint.file 导入文件

url = ' https://company.sharepoint.com '
用户名 = ' [email protected] '
密码 = 'xxx'

ctx_auth = AuthenticationContext(url)

如果 ctx_auth.acquire_token_for_user(用户名,密码):
ctx = ClientContext(url, ctx_auth)
网络 = ctx.web
...

此页面是否有帮助?
0 / 5 - 0 等级