在python中读取'instance'类型的数据

2024-09-27 04:23:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用this库阅读python中的gmail收件箱。这是我收到的每封邮件的回复:

From nobody Mon Dec 26 16:42:46 2016
Delivered-To: someone@examplemail.com
Received: by 10.28.211.66 with SMTP id ferf98er9fef9fr;
.
.
.
X-Source-Dir: erferfefefrref:/public_html
X-CMAE-Envelope: grtgrtgrtgrtgrt......

This is the message body

在检查响应的对象类型时,它返回<type 'instance'>

我可以使用此代码读取Subject, Delivered-To, Received, X-Source-Dir之类的属性

print response['subject']
print response['delivered-to']

但无法读取消息体(在给定示例中为This is the message body

图书馆的文件说我们可以用

print response.body

但这似乎不起作用,反而产生了这个错误:

Message instance has no attribute 'body'

有没有其他方法可以从上面的数据中提取尸体??你知道吗


Tags: thetoinstancesourcemessageisresponsedir
1条回答
网友
1楼 · 发布于 2024-09-27 04:23:08

从您在问题中链接的页面:

unread = g.inbox().mail(unread=True)
print unread[0].body
# None

unread[0].fetch()
print unread[0].body

这对你不管用吗?你知道吗

相关问题 更多 >

    热门问题