【发布时间】:2019-07-18 22:58:33
【问题描述】:
Teams 似乎缺乏将文件镜像到共享目录的任何本机方式。我正在尝试使用 Python(或其他语言,但首选 Python!):
一个。使用 Python 直接从微软团队拉入内存,用 Pandas 处理
b.将团队中的文件复制到共享网络文件夹(Python 可以随后读取)
我发现了这个,但无法让它与团队一起使用 - 团队 URL 看起来不像这些。 How to read SharePoint Online (Office365) Excel files in Python with Work or School Account?
这似乎接近我想要做的。我还在 PyPi 存储库上找到了“pymsteams”。 https://pypi.org/project/pymsteams/ 似乎只是让您向 Teams 发送消息而不是其他任何东西?除非我误解了什么。
https://pypi.org/project/Office365-REST-Python-Client/
https://pypi.org/project/pymsteams/
from office365.runtime.auth.authentication_context
import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.file import File
url = 'https://teams.microsoft.com/l/file'
username = 'myusername'
password = 'mypassword'
relative_url ='myurl'
ctx_auth = AuthenticationContext(url)
ctx_auth.acquire_token_for_user(username, password)
尝试运行上面的代码给出 AttributeError: 'NoneType' 对象没有属性 'text'
完整的堆栈跟踪:
runfile('H:/repos/foo/untitled0.py', wdir='H:/repos/foo')
Traceback (most recent call last):
File "<ipython-input-35-314ab7dc63c9>", line 1, in <module>
runfile('H:/repos/foo/untitled0.py', wdir='H:/foo/image_ai')
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "H:/repos/image_ai/untitled0.py", line 10, in <module>
ctx_auth.acquire_token_for_user(username, password)
File "C:\ProgramData\Anaconda3\lib\site-packages\office365\runtime\auth\authentication_context.py", line 18, in acquire_token_for_user
return self.provider.acquire_token()
File "C:\ProgramData\Anaconda3\lib\site-packages\office365\runtime\auth\saml_token_provider.py", line 57, in acquire_token
self.acquire_service_token(options)
File "C:\ProgramData\Anaconda3\lib\site-packages\office365\runtime\auth\saml_token_provider.py", line 88, in acquire_service_token
token = self.process_service_token_response(response)
File "C:\ProgramData\Anaconda3\lib\site-packages\office365\runtime\auth\saml_token_provider.py", line 119, in process_service_token_response
return token.text
AttributeError: 'NoneType' object has no attribute 'text'
【问题讨论】:
-
你能显示整个堆栈跟踪吗?
-
谢谢,我添加了完整的堆栈跟踪。
-
对我来说似乎是一个身份验证错误
-
所有 Microsoft Teams 文件都存储在 SharePoint 上,因此您应该使用 Microsoft Graph APIs for OneDrive and SharePoint。这是Send and receive files through your bot 上的文档。
-
机器人仅适用于个人聊天,不适用于频道中发布的文件。
标签: python-3.x office365 office365api microsoft-teams