运行时错误:未找到身份验证令牌。需要 o365 python 的身份验证流程

时间:2021-05-06 03:25:52

标签: python linux office365api

我正在使用 Linux 机器在 Linux 终端内运行 python 脚本。 如果我在包含我的 python 脚本的目录中打开终端,然后使用 python3 availableHoursReporting.py 命令脚本运行没有任何问题。

但是,如果我在存放我的 python 脚本的目录之外打开一个终端会话,那么我得到 RuntimeError: No auth token found. Authentication Flow needed

我的Linux机器上的目录结构如下:

/home/ubuntu/python_scripts/Available-Hours-Reporting-/

'auth_token' 存储在 Available-Hours-Reporting 文件夹中

相关代码如下:

import o365
from o365 import Account

credentials = ('xxxxxxxxx',)

account = Account(credentials, auth_flow_type = 'public')
account.connection.get_session(load_token = True)

追溯:

Traceback (most recent call last):
  File "/home/ubuntu/python_scripts/Available-Hours-Reporting-/availableHoursReporting.py", line 27, in <module>
    account.connection.get_session(load_token = True)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/O365/connection.py", line 563, in get_session
    raise RuntimeError('No auth token found. Authentication Flow needed')
RuntimeError: No auth token found. Authentication Flow needed

我是 Linux 新手,所以我不确定我是否完全误解了文件夹结构,或者我是否正确使用终端来执行 .py 脚本。

1 个答案:

答案 0 :(得分:1)

你有两种解决方法。
方法一。

/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]{3,}+@[a-zA-Z0-9-]+(?:[A-Z0-9-]+\.)+[A-Z]{2,5}$/

方法 2. 不使用 FileSystemTokenBackend 的实例

from o365.utils.token import FileSystemTokenBackend
tk = FileSystemTokenBackend(token_path="your token path", token_filename="filename")
account = Account(credentials, auth_flow_type = 'public',token_backend=tk)

您可以在“connection.py”的源代码中找到详细信息。 token_path 应该是完整的绝对路径。