Error (UnicodeDecodeError) python2 items that appear UnicodeDecodeError: 'ascii' codec can not decode byte 0x ?? in position 1

He ran a python2 of ERP

Just start django appeared bug

UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1

No way to change from

Rush to Baidu a bit

The original is that we have this problem

python2.7 interpreter comes the problem

and so

Here are solutions

python during installation, the default encoding is ascii, when non-ascii coding occurs in a program, python treatment often report such a mistake UnicodeDecodeError: 'ascii' codec can not decode byte 0x ?? in position 1: ordinal not in range (128), python can not handle non-ascii-encoded, this time need to set the default encoding of python, generally set the utf8 encoding format.
  Query system default encoding type the following command in the interpreter:
Python Code
  >>> sys.getdefaultencoding () 
  is provided to use the default encoding:
Python Code
  >>> sys.setdefaultencoding ( 'utf8') 
  may report AttributeError: 'module' object has no attribute 'setdefaultencoding' mistakes. Execution reload (SYS) , and then execute the above command will be passed.
Until then execute sys. getdefaultencoding () will find the encoding utf8 has been set up, but the interpreter modify code can only be guaranteed when times effective, after a restart interpreter, you will find, coding has been reset to the default ascii.
  There are two ways to set the default encoding python:
  a solution to the problem by adding the following codes in the program:
  the Python Code
  # = UTF8 encoding 
  Import SYS 
  reload (SYS) 
  sys.setdefaultencoding ( 'utf8') 
  Another option is to create a sitecustomize.py in Lib \ site-packages folder python, the content:
  the Python Code 
  # = UTF8 encoding 
  Import SYS
  reload (SYS) 
  sys.setdefaultencoding ( 'UTF8 ') 
  at this time, restart the python interpreter, execution sys.getdefaultencoding (), it found that the coding has been set in the utf8, after multiple restart, the same effect, because the system when the python started, call the file itself, provided the default coding system, without the need to manually add each time resolution code, once belonging solutions.

 

 

After this error occurred

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0: invalid continuation byte

 

I went to put into a utf-8 gbk

Then the project up

But there are still wrong project

Tears

Guess you like

Origin www.cnblogs.com/wjw6692353/p/11605161.html