2016-12-27 26 views
0

我使用this庫來讀取python中的gmail收件箱。這是我收到的郵件每響應:在python中讀取'instance'類型的數據

From nobody Mon Dec 26 16:42:46 2016 
Delivered-To: [email protected] 
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'>

我能夠使用此代碼

print response['subject'] 
print response['delivered-to'] 
Subject, Delivered-To, Received, X-Source-Dir讀取屬性

但無法讀取消息正文(在給定示例中爲This is the message body

庫的文檔說,我們可以使用

print response.body 

得到身體,但似乎並沒有工作,並給出了這個錯誤,而不是:

消息實例沒有屬性「身體」

是有沒有其他方法可以從上面的數據中提取身體?

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

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

這是不是爲你工作:

+1

這個庫的開放源代碼和檢查 - 也許它有不同的名稱或使用函數像'get_body()'。 – furas

+3

順便說一句:你也可以檢查'print dir(response)'來查看這個對象中的方法。 – furas

+0

謝謝@furas謝謝:)幫助,找到一個功能做同樣的! – mrid

回答

0

從頁面你在你的問題掛鉤?

+0

我試過了,但沒有工作 – mrid

+0

看起來它在3年內還沒有更新。這可能值得尋找更新的選項。 –

+0

正如@furas上面提到的,嘗試查看對象的方法。祝你好運! –

相關問題