zhangyunhao116 / zmail

Zmail makes it easier to send and retrieve emails in python3
MIT License
433 stars 111 forks source link

将pyecharts生成的html文件作为附件时,显示GBK解码错误 #40

Closed jaystone776 closed 5 years ago

jaystone776 commented 6 years ago

pyecharts生成的html文件是utf8的可视化图形 UnicodeDecodeError Traceback (most recent call last)

in () 6 'attachments':'C:\data\report.html' ……… ~\Anaconda3\lib\site-packages\zmail\il\message.py in in _get_attachment_part(file) 189 if main_type == 'text': 190 with open(file, 'r') as f: --> 191 part = MIMEText(xt(f.read()) ()) 192 part['Content-Disposition'] = 'attachment;filename="%s"' % encoded_name 193 UnicodeDecodeError: 'gbk' codec can't decode byte 0xbd in position 1 请问怎么解决?谢谢
jaystone776 commented 6 years ago

自问自答: 我在这里190 with open(file, 'r') as f: 加了个encoding = “utf8” ,改成 with open(file, 'r',encoding ="utf8") as f:就可以了,但估计会影响其他编码的文件,还请作者有空看一下,有没有更好的解决方案,谢谢啦

zhangyunhao116 commented 6 years ago

估计是html文件和邮件的编码不同导致的 后续会修复这个问题 谢谢反馈~

jaystone776 commented 6 years ago

附件的编码是utf8的

zhangyunhao116 commented 5 years ago

请尝试安装0.2.0版本 这个版本修复了很多问题 如果更新后还能复现 请重新打开这个issue

jaystone776 commented 5 years ago

装了zmail 0.20,还是不行,用的是Python 3.7.1


UnicodeDecodeError Traceback (most recent call last)

in 5 'attachments': "tk.html" 6 } ----> 7 pkfare.send_mail(mail_to, mail) ~\.virtualenvs\lib\site-packages\zmail\server.py in send_mail(self, recipients, mail, timeout, auto_add_from, auto_add_to) 96 97 if (auto_add_from or self.auto_add_from) and _mail.mail.get('From') is None: ---> 98 _mail.set_mime_header('From', '{}<{}>'.format(self.username.split("@")[0], self.username)) 99 100 recipients = recipients if isinstance(recipients, (list, tuple)) else (recipients,) ~\.virtualenvs\lib\site-packages\zmail\mime.py in set_mime_header(self, k, v) 96 self.mime[k] = v 97 else: ---> 98 self.make_mine() 99 self.mime[k] = v 100 ~\.virtualenvs\lib\site-packages\zmail\mime.py in make_mine(self) 78 if isinstance(attachment, str): 79 attachment_abs_path = get_abs_path(attachment) ---> 80 part = make_attachment_part(attachment_abs_path) 81 mime.attach(part) 82 elif isinstance(attachment, tuple): ~\.virtualenvs\lib\site-packages\zmail\mime.py in make_attachment_part(file_path) 133 if main_type == 'text': 134 with open(file_path, 'r') as f: --> 135 part = MIMEText(f.read()) 136 part['Content-Disposition'] = 'attachment;filename="{}"'.format(encoded_name) 137 UnicodeDecodeError: 'gbk' codec can't decode byte 0xbd in position 20784: illegal multibyte sequence
jaystone776 commented 5 years ago

这个issue估计还得开一下

zhangyunhao116 commented 5 years ago

1.麻烦提供一下报错的环境(系统、python版本、zmail版本) 2.如果可以 能提供一份报错样例吗

jaystone776 commented 5 years ago

zmail 0.20, Python 3.7.1

jaystone776 commented 5 years ago

附件样本已发邮件

zhangyunhao116 commented 5 years ago

你好 附件我尝试了一下 在zmail 0.2.1版本下成功发送,测试系统是Linux,GBK一般是在WINDOWS下的中文编码,请问发送的时候是否重命名或者有一些其他的操作呢?