【问题标题】:Python - Download files from Share Point | Authentication token errorPython - 从 Share Point 下载文件 |身份验证令牌错误
【发布时间】:2020-03-25 03:47:22
【问题描述】:

我正在处理一个报告自动化项目,我需要从共享点位置自动下载 excel 文件。我尝试了一些引用Python - Download files from SharePoint site 的示例,但在导入的库函数中出现错误。请告诉我,我在这里缺少什么。

错误:

回溯(最近一次通话最后一次):
文件“worklod_report.py”,第 66 行,在
if ctxAuth.acquire_token_for_user(用户名='murali.pandiyan@xyz.com', 密码=pwd):
文件“C:\Users\murali.pandiyan\AppData\Local\Programs\Python\Python37-32\lib\site- packages\office365\runtime\auth\authentication_context.py",第 18 行,在 acquire_token_for_user 返回 self.provider.acquire_token()
文件“C:\Users\murali.pandiyan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\office365\runtime\auth\saml_token_provider.py”,第 57 行,在 acquire_token
self.acquire_service_token(选项)
文件“C:\Users\murali.pandiyan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\office365\runtime\auth\saml_token_provider.py”,第 88 行,在 acquire_service_token
token = self.process_service_token_response(response)
文件“C:\Users\murali.pandiyan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\office365\runtime\auth\saml_token_provider.py”,第 119 行,在 process_service_token_response
返回 token.text
AttributeError: 'NoneType' 对象没有属性 'text'

Python 代码:

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
import getpass

if __name__ == '__main__':
    ctxAuth = AuthenticationContext(url='https://internal.abc.net/sites/Compute/')
    print("Enter Password:")
    pwd=getpass.getpass()
    if ctxAuth.acquire_token_for_user(username='murali.pandiyan@xyz.com', password=pwd):
        ctx = ClientContext(settings['url'], ctxAuth)
        print("Authentication is success")
    else:
        print(ctxAuth.get_last_error())

【问题讨论】:

  • 您好,您确定SP服务器可用吗?
  • 是的,我可以从浏览器访问它
  • 您的身份验证正确进行。如果不检查您的凭据

标签: python sharepoint


【解决方案1】:

以下代码sn-p供大家参考。

if __name__ == '__main__':
    ctxAuth = AuthenticationContext('https://internal.abc.net/sites/Compute/')
    print("Enter Password:")
    pwd=getpass.getpass()
    if ctxAuth.acquire_token_for_user('murali.pandiyan@xyz.com', pwd):
        ctx = ClientContext(settings['url'], ctxAuth)
        print("Authentication is success")
    else:
        print(ctxAuth.get_last_error())

在这里查看认证源代码:authentication_context.py

文件下载源代码在这里:file_operations.py

【讨论】:

  • 感谢您的回复。在调查该问题时,发现 PowerShell 脚本能够验证并从 SharePoint 下载文件。 PS脚本将明文密码转换为安全字符串,然后传递给认证方法。
  • 尝试使用 py-securestring 模块在 python 中复制相同的内容,但示例似乎不起作用。请就如何进行安全字符串身份验证提出建议
猜你喜欢
  • 2014-06-18
  • 2021-09-23
  • 2015-07-02
  • 2019-02-16
  • 2019-07-12
  • 1970-01-01
  • 2011-12-01
  • 2019-08-12
相关资源
最近更新 更多