Python UnicodeDecodeError 解决办法
2013-12-20 14:45
260 查看
背景
最近在学习django,今天在启动django admin的时候,发现admin 默认的css没有加载到,然后一直报这个错误,然后去Google。
开始以为是css路径的问题,就各种改settings下的路径设置,发现怎么改也不对,后来经过一上午的搜索,发现这是Python 2.x 的bug。
抛异常的具体信息如下:
File "D:\Program Files\Python 2.7\lib\mimetypes.py", line 249, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xbc in position 0: ordinal not in range(128)
解决办法:
根据提示打开 \Python 2.x\lib\mimetypes.py
def enum_types(mimedb):
i = 0
while True:
try:
ctype = _winreg.EnumKey(mimedb, i)
except EnvironmentError:
break
#try:
#ctype = ctype.encode(default_encoding) # omit in 3.x!
#except UnicodeEncodeError:
#pass
else:
yield ctype
i += 1
如上,注释或者去掉其中的
try:
ctype = ctype.encode(default_encoding) # omit in 3.x!
except UnicodeEncodeError:
pass然后重新运行django admin即可
参考自 http://stackoverflow.com/questions/4237898/unicodedecodeerror-ascii-codec-cant-decode-byte-0xe0-in-position-0-ordinal
Python 官方bug描述 http://bugs.python.org/issue10490
最近在学习django,今天在启动django admin的时候,发现admin 默认的css没有加载到,然后一直报这个错误,然后去Google。
开始以为是css路径的问题,就各种改settings下的路径设置,发现怎么改也不对,后来经过一上午的搜索,发现这是Python 2.x 的bug。
抛异常的具体信息如下:
File "D:\Program Files\Python 2.7\lib\mimetypes.py", line 249, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xbc in position 0: ordinal not in range(128)
解决办法:
根据提示打开 \Python 2.x\lib\mimetypes.py
def enum_types(mimedb):
i = 0
while True:
try:
ctype = _winreg.EnumKey(mimedb, i)
except EnvironmentError:
break
#try:
#ctype = ctype.encode(default_encoding) # omit in 3.x!
#except UnicodeEncodeError:
#pass
else:
yield ctype
i += 1
如上,注释或者去掉其中的
try:
ctype = ctype.encode(default_encoding) # omit in 3.x!
except UnicodeEncodeError:
pass然后重新运行django admin即可
参考自 http://stackoverflow.com/questions/4237898/unicodedecodeerror-ascii-codec-cant-decode-byte-0xe0-in-position-0-ordinal
Python 官方bug描述 http://bugs.python.org/issue10490
相关文章推荐
- python里面的字典dict类型键名为中文的解决办法
- VS2015 下python编程,报错:'utf-8' codec can't decode byte,解决办法?
- Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法
- 【python】f.write()写入中文出错解决办法
- Error: Can't find Python executable "python", you can set the PYTHON env variable.解决办法
- python抓网页被网站拒绝的解决办法
- linux下Python各种关于路径问题的解决办法
- Python下调用json.dumps中文显示问题解决办法
- python UnicodeEncodeError: 'ascii' codec can't encode characters 解决办法
- python3使用pickle读取文件提示TypeError或者UnicodeDecodeError的解决办法
- python 处理中文路径终极解决办法
- Python+Selenium定位不到元素常见原因及解决办法(报:NoSuchElementException)
- 【总结】Python 2.x中常见字符编码和解码方面的错误及其解决办法
- 安装Python3.6,api-ms-win-crt-runtime-l1-1-0.dll 丢失解决办法
- Python CSV文件乱码解决办法
- 安装常见python包,出现的问题,及其解决的办法
- Ubuntu16.04上使用Anaconda3的Python3.6的pip安装UWSGI报错解决办法
- Python下json中文乱码解决办法
- Python学习笔记 --- 'password' is an invalid keyword argument for this function解决办法
- SecureCRT 中 python 命令行使用退格键(backspace)出现 ^H 解决办法