Python ez_install : UnicodeDecodeError: 'ascii' codec can't decode byte 0xae in position 11

[亡魂溺海] 提交于 2019-11-27 06:28:00

问题


Getting the error below trying to install ez_install, Windows 7 64 bit machine with fresh Python 2.7. Any ideas?

Installing Setuptools
Traceback (most recent call last):
  File "setup.py", line 17, in 
    exec(init_file.read(), command_ns)
  File "", line 8, in 
  File "c:\users\namar\appdata\local\temp\tmp1tanvy\setuptools-2.1\setuptools\__
init__.py", line 11, in 
    from setuptools.extension import Extension
  File "c:\users\namar\appdata\local\temp\tmp1tanvy\setuptools-2.1\setuptools\ex
tension.py", line 5, in 
    from setuptools.dist import _get_unpatched
  File "c:\users\namar\appdata\local\temp\tmp1tanvy\setuptools-2.1\setuptools\di
st.py", line 15, in 
    from setuptools.compat import numeric_types, basestring
  File "c:\users\namar\appdata\local\temp\tmp1tanvy\setuptools-2.1\setuptools\co
mpat.py", line 19, in 
    from SimpleHTTPServer import SimpleHTTPRequestHandler
  File "c:\python27\lib\SimpleHTTPServer.py", line 27, in 
    class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  File "c:\python27\lib\SimpleHTTPServer.py", line 208, in SimpleHTTPRequestHand
ler
    mimetypes.init() # try to read system mime.types
  File "c:\python27\lib\mimetypes.py", line 358, in init
    db.read_windows_registry()
  File "c:\python27\lib\mimetypes.py", line 258, in read_windows_registry
    for subkeyname in enum_types(hkcr):
  File "c:\python27\lib\mimetypes.py", line 249, in enum_types
    ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xae in position 11: ordinal
 not in range(128)
Something went wrong during the installation.
See the error message above.


C:\Users\namar\Downloads>cd\

C:\>cd Python27

回答1:


I met the same problem, solved it by deleting non-ASCII character in window registry "HKEY_CLASSES_ROOT\MIME\Database\Content Type" and it works.The reason is

 ctype = ctype.encode(default_encoding)  

will throw UnicodeDecodeError when it met non-ASCII characters and the program will stop.




回答2:


Check this link.(http://blog.csdn.net/hugleecool/article/details/17996993).

In C:\Python27\Lib\mimetypes.py find next string

default_encoding = sys.getdefaultencoding()

replace it with

if sys.getdefaultencoding() != 'gbk':  
    reload(sys)  
    sys.setdefaultencoding('gbk')  
default_encoding = sys.getdefaultencoding()

Notice: instead 'gbk' choose your encoding.




回答3:


In C:\Python27\Lib\mimetypes.py find next string

default_encoding = sys.getdefaultencoding()

replace it with

if sys.getdefaultencoding() != 'gbk':  
    reload(sys)  
    sys.setdefaultencoding('gbk')  
default_encoding = sys.getdefaultencoding()

Notice: instead 'gbk' choose your encoding.

The above answer satisfies my case of unicode decode error in using google app engine local web server for php and python .




回答4:


In my case, simply comment the following four line worked,

try:
    ctype = ctype.encode(default_encoding) # omit in 3.x!
except UnicodeEncodeError:
    pass

And replace UnicodeEncodeError to be UnicodeError worked.

For more info, you can check this question.



来源:https://stackoverflow.com/questions/21248225/python-ez-install-unicodedecodeerror-ascii-codec-cant-decode-byte-0xae-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!