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

Read data of type 'instance' in 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

在检查响应的对象类型时,它 returns <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'

有没有其他方法可以从上面的数据中提取正文??

来自您在问题中链接的页面:

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

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

这对你不起作用吗?