fra*_* hk 0 python django unicode character-encoding python-3.x
\u2264 这是字符(小于或等于),这是错误的根本原因。详细错误日志:
Traceback (most recent call last):
File "C:\Dev\EXE\TEMP\cookie\crumbs\views.py", line 1520, in parser
html_file.write(html_text)
File "C:\Users\Cookie1\AppData\Local\Programs\Python\Python36-32\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2264' in position 389078: character maps to <undefined>
Run Code Online (Sandbox Code Playgroud)
错误消息表明您正在尝试编码为Windows-1252字符编码。该编码没有小于或等于符号的表示形式。
>>> "\u2264".encode("cp1252")
>>> Traceback... [as above]
Run Code Online (Sandbox Code Playgroud)
答案是使用不受限制的编码UTF-8,而不是受严格限制的Windows-1252。
您的问题并没有包含太多上下文,但是这一行html_file.write(html_text)让我觉得您正在使用Python的文件协议。的文档open()显示了如何设置编码,例如
html_file = open("file.html", mode="w", encoding="utf8")
Run Code Online (Sandbox Code Playgroud)
请注意,“默认编码取决于平台(无论locale.getpreferredencoding()返回什么)”,这就是为什么在Windows 7上使用Windows-1252的原因。
| 归档时间: |
|
| 查看次数: |
364 次 |
| 最近记录: |