【发布时间】:2022-09-23 23:30:49
【问题描述】:
链接:https://github.com/O365/python-o365
调用 account.authenticate。此调用将为您请求一个令牌,并且 将其存储在后端。不需要用户交互。方法 将令牌存储在后端并返回 True 如果 认证成功。
我在 python 中创建了一个后台服务,它使用 python 和 O365 发送电子邮件。
当我运行以下命令时,它给了我一个令牌丢失的错误:
from O365 import Account credentials = (\'my_client_id\', \'my_client_secret\') account = Account(credentials, auth_flow_type=\'credentials\', tenant_id=\'my-tenant-id\') # if account.authenticate(): # print(\'Authenticated!\') mailbox = account.mailbox(\'sender@mailbox.com\') inbox = mailbox.inbox_folder() m = mailbox.new_message() m.to.add(\'recep@mailbox.com\') m.subject = \'My subject\' m.body = \'My email\' m.send()当我添加
.authenticate时,如下所示,发送电子邮件就可以了。from O365 import Account credentials = (\'my_client_id\', \'my_client_secret\') account = Account(credentials, auth_flow_type=\'credentials\', tenant_id=\'my-tenant-id\') if account.authenticate(): print(\'Authenticated!\') mailbox = account.mailbox(\'sender@mailbox.com\') inbox = mailbox.inbox_folder() m = mailbox.new_message() m.to.add(\'recep@mailbox.com\') m.subject = \'My subject\' m.body = \'My email\' m.send()当我评论以下行
.authenticate并运行它的程序时:from O365 import Account credentials = (\'my_client_id\', \'my_client_secret\') account = Account(credentials, auth_flow_type=\'credentials\', tenant_id=\'my-tenant-id\') # if account.authenticate(): # print(\'Authenticated!\') mailbox = account.mailbox(\'sender@mailbox.com\') inbox = mailbox.inbox_folder() m = mailbox.new_message() m.to.add(\'recep@mailbox.com\') m.subject = \'My subject\' m.body = \'My email\' m.send()为什么程序一开始就失败了,最后还是同一个程序工作了?
标签: python python-3.x python-o365