gpt4 book ai didi

python - 权限不足,无法通过 Gmail API 删除邮件

转载 作者:太空狗 更新时间:2023-10-30 02:20:06 24 4
gpt4 key购买 nike

我的代码应该在我的收件箱中接收一条消息,检查它的链接,然后从电子邮件中提取链接,然后将其删除。

message = gmail_service.users().messages().get(userId='me', id=thread['id'], format='raw').execute()    #get message using thread id
msg_str = base64.urlsafe_b64decode(message['raw'].encode('ASCII'))
msg = email.message_from_string(msg_str)
for part in msg.walk():
msg.get_payload()
if part.get_content_type() == 'text/html':
mytext = base64.urlsafe_b64decode(part.get_payload().encode('UTF-8'))
html = BeautifulSoup(mytext)
for link in html.find_all('a'):
mylink = link.get('href')
print mylink
try:
service.users().messages().trash(userId='me', id=thread['id']).execute()
print 'Message with id: %s trashed successfully.' % msg_id
except errors.HttpError, error:
print 'Could not trash ' + thread['id'] + ': %s' % error

我在我的代码中定义的范围是.modify,它应该给我垃圾邮件所需的权限without fail .为什么我收到错误:

<HttpError 403 when requesting https://www.googleapis.com/gmail/v1/users/me/messages/147d8c9a6348e437/trash?alt=json returned "Insufficient Permission">

编辑:即使是 documented example返回 403 禁止错误,这一定是 Gmail API 本身的错误。

最佳答案

在过去的某个时候,您在同一目录中注册了只读范围,这被缓存在名为 gmail.storage 的文件中。

将该文件移开并再次运行您的程序,它应该可以工作。

关于python - 权限不足,无法通过 Gmail API 删除邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25324955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com