2017-10-26 13 views
0

Ich habe ähnliche Threads hier gesehen, kann aber nicht herausfinden, wie dies funktioniert.Pandas DataFrame mit Python senden

Ich mag einen Pandas Datenrahmen in eine E-Mail kapseln und sie versenden .. Ich mag, dass die Tabelle in der E-Mail als eine Tabelle zeigen, nicht als Anhang

So etwas wie dies in dem Körper der E-Mail :

enter image description here

ich habe versucht, den folgenden Beispielcode, aber ich halte einen Fehler bekommen:

--------------------------------------------------------------------------- 
AttributeError       Traceback (most recent call last) 
<ipython-input-33-e766c6012525> in <module>() 
    31 
    32 
---> 33 msg = MIMEText(content, text_subtype) 
    34 msg['Subject']=  subject 
    35 msg['From'] = sender # some SMTP servers will do this automatically, not all 

C:\Program Files\Anaconda3\lib\email\mime\text.py in __init__(self, _text, _subtype, _charset) 
    32   if _charset is None: 
    33    try: 
---> 34     _text.encode('us-ascii') 
    35     _charset = 'us-ascii' 
    36    except UnicodeEncodeError: 

AttributeError: 'function' object has no attribute 'encode' 

Hier ist der Code

import pandas as pd 

Import_MICS="https://www.iso20022.org/sites/default/files/ISO10383_MIC/ISO10383_MIC.csv" 
MICS=pd.read_csv(Import_MICS,sep=",") 

SMTPserver = 'email-smtp.us-east-2.amazonaws.com' 
sender =  'x.com' 
destination = ['x.com'] 

USERNAME = "efsdff" 
PASSWORD = "sfdfsf" 

# typical values for text_subtype are plain, html, xml 
text_subtype = 'html' 


content="""\ 
Test message number 2 
""" 
content=MICS.to_html 
subject="Sent from Python" 

import sys 
import os 
import re 

from smtplib import SMTP_SSL as SMTP  # this invokes the secure SMTP protocol (port 465, uses SSL) 
from email.mime.text import MIMEText 


msg = MIMEText(content, text_subtype) 
msg['Subject']=  subject 
msg['From'] = sender # some SMTP servers will do this automatically, not all 



conn = SMTP(SMTPserver) 
conn.set_debuglevel(False) 
conn.starttls 
conn.login(USERNAME, PASSWORD) 
conn.sendmail(sender, destination, msg.as_string()) 

Irgendwelche Ideen auf, wie viel

Dank geschätzt zu beheben wäre!

Antwort

0
content=MICS.to_html 

sollte

content=MICS.to_html() 

Ich musste auch Codierung für die csv hinzufügen:

MICS=pd.read_csv(Import_MICS,encoding = 'ISO-8859-1')