0
我正在嘗試向SMS網關電子郵件發送電子郵件+附件。然而,我目前正在得到一個Unicode解碼:Error'Charmap'編解碼器無法解碼位置60的字節0x8dUnicodeDecodeError Python 3.5.1電子郵件腳本
我不知道如何去解決這個問題,並會對您的建議感興趣。波紋管是我的代碼和完整的錯誤。
import smtplib, os
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
msg = MIMEMultipart()
msg['Subject'] = 'Cuteness'
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg.preamble = "Would you pet me? I'd Pet me so hard..."
here = os.getcwd()
file = open('cutecat.png')#the png shares directory with actual script
for here in file: #Error appears to be in this section
with open(file, 'rb') as fp:
img = MIMImage(fp.read())
msg.attach(img)
s = smtplib.SMTP('Localhost')
s.send_message(msg)
s.quit()
""" Traceback (most recent call last):
File "C:\Users\Thomas\Desktop\Test_Box\msgr.py", line 16, in <module>
for here in file:
File "C:\Users\Thomas\AppData\Local\Programs\Python\Python35-32\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 60: character maps to <undefined>"""
哎呀!是的,我忘了我把它留在那裏,我很早就遇到了麻煩,忘記了解決這個問題。在這一天,我一直在做另一個項目8個小時,並開始變得懶惰。 – Villagesmithy