How to fix: “UnicodeDecodeError: 'ascii' codec can't decode byte”

前端 未结 19 1584
谎友^
谎友^ 2020-11-22 01:21
as3:~/ngokevin-site# nano content/blog/20140114_test-chinese.mkd
as3:~/ngokevin-site# wok
Traceback (most recent call last):
File \"/usr/local/bin/wok\", line 4, in
         


        
19条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 02:01

    Finally I got it:

    as3:/usr/local/lib/python2.7/site-packages# cat sitecustomize.py
    # encoding=utf8  
    import sys  
    
    reload(sys)  
    sys.setdefaultencoding('utf8')
    

    Let me check:

    as3:~/ngokevin-site# python
    Python 2.7.6 (default, Dec  6 2013, 14:49:02)
    [GCC 4.4.5] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> reload(sys)
    
    >>> sys.getdefaultencoding()
    'utf8'
    >>>
    

    The above shows the default encoding of python is utf8. Then the error is no more.

提交回复
热议问题