Python報錯UnicodeDecodeError: ascii codec can t decophp
摘自python
Python報錯UnicodeDecodeError: ascii codec can t decode byte 0xe0 ...解決方法.net
在報錯的頁面添加代碼:code
import sys reload(sys) sys.setdefaultencoding('utf8')
Windows 8機器上安裝Python2.7後,下載一些Package包進行setup時老是報錯UnicodeDecodeError,以下:htm
File "C:/Python27/lib/mimetypes.py", line 250, in enum_types ctype = ctype.encode(default_encoding) # omit in 3.x! UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)
在網上搜索到的解決方法以下:ci
1. 這是Python 2 mimetypes的bugget
#沒找到第二個文件的地方it
2. 須要將Python2.7/lib/mimetypes.py文件中以下片斷註釋或刪除:io
try: ctype = ctype.encode(default_encoding) # omit in 3.x! except UnicodeEncodeError: pass
在報錯的頁面添加代碼:class
import sys reload(sys) sys.setdefaultencoding('utf8')
執行 Python ez_setup.py,報錯:
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb0 in position 35: invalid start byte
解決辦法:
在報錯的頁面添加代碼:
import sys reload(sys) sys.setdefaultencoding('gb18030')
而後再執行 Python ez_setup.py,成功了。