简体   繁体   English

UnicodeDecodeError:“ ascii”编解码器无法解码字节0xe3

[英]UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 UnicodeDecodeError:“ ascii”编解码器无法解码字节0xe3

I am facing this issue while running a mailing script in py 2.7 for the line... 我在py 2.7中为该行运行邮件脚本时遇到了这个问题...

msg.attach(MIMEText(welcome_msg + htmlMessageContent + footer_msg, 'html')) msg.attach(MIMEText(welcome_msg + htmlMessageContent + footer_msg,'html'))

One of the elements of the string you are concatenating 您要连接的字符串的元素之一

welcome_msg + htmlMessageContent + footer_msg

is Unicode, and another of them isn't. 是Unicode,而另一个不是。 When you concatenate the strings Python has convert them all to a common type (Unicode), much as it does when you add an integer to a float. 当您连接字符串时,Python会将它们全部转换为通用类型(Unicode),这与将整数添加到浮点数中的方式很相似。 But the default string conversion to Unicode is ascii, and if the string contains a non-ascii character it will fail. 但是,默认的字符串转换为Unicode是ascii,如果该字符串包含非ascii字符,它将失败。

Find out which string isn't Unicode. 找出哪个字符串不是Unicode。 For this you can use type() . 为此,您可以使用type() Wrap that string in a call to unicode() that explains how you want '\\xe3' interpreted. 将该字符串包装到对unicode()的调用中,该调用解释了如何解释'\\xe3' For example, if '\\xe3' should be interpreted as 'ã' : 例如,如果'\\xe3'应解释为'ã'

unicode(mystring, encoding='Latin-1')

Then your concatenation should work. 然后,您的串联应该起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UnicodeDecodeError:'utf-8'编解码器无法解码位置34的字节0xe3:无效的连续字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 34: invalid continuation byte UnicodeDecodeError:'utf-8'编解码器无法解码位置1中的字节0xe3:无效的连续字节 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 1: invalid continuation byte Q: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 0: 意外的数据结束 - Q: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 0: unexpected end of data Pymysql UnicodeDecodeError:“utf-8”编解码器无法解码字节 0xe3 - Pymysql UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 UnicodeDecodeError:“ ascii”编解码器无法解码字节0xe4 - UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 ascii编解码器无法在Ubuntu / Python中解码位置错误中的字节0xe3,但不能在OS X / Python上解码 - ascii codec can't decode byte 0xe3 in position error in Ubuntu/Python, but not on OS X/Python Python-Ascii编解码器无法在位置0解码字节0xe3:序数不在范围内(128) - Python - ascii codec can't decode byte 0xe3 in position 0: ordinal not in range(128) 得到错误:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 1: invalid continuation byte, playsound - Got the error:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 1: invalid continuation byte, playsound UnicodeDecodeError:“ ascii”编解码器无法解码字节 - UnicodeDecodeError: 'ascii' codec can't decode byte Python 3 UnicodeDecodeError:'ascii'编解码器无法解码位置0中的字节0xe2:序数不在范围内(128) - Python 3 UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM