1. The cause of the abnormality
This is an error related to python
Because by default, Python uses the ascii encoding method, and when Python converts between encoding methods, it will use unicode as the “intermediate encoding”, but the maximum unicode is only as long as 128, so here when trying to encode ascii characters When the string was converted into “intermediate code” unicode, the above error was reported because it exceeded its range.
Two, the solution
Add a sitecustomize.py file in the /usr/lib/python2.7/site-packages/ directory, the content is as follows:
import sys sys.setdefaultencoding( ' utf-8 ' )
Read More:
- [Solved] Grid Search Error (GridSearchCV): ‘ascii‘ codec can‘t encode characters in position 18-20: ordinal not in r
- How to Solve Pytorch DataLoader Loading Error: UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xe5 in position 1023
- [Solved] UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xbf in position 7: invalid start byte
- [Solved] SyntaxError: (unicode error) ‘utf-8’ codec can’t decode byte 0xbe in position 0
- Django CSV file Error: UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xb5 in position 0: invalid start
- SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated \UX
- [Solved] SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 6-7: malformed
- [Solved] SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 10-11: malformed
- SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3: truncated \UX
- Python Error: SyntaxError: (unicode error) ‘unicodeescape‘ codec can‘t decode bytes in position 2-3:
- SyntaxError: Non-ASCII character ‘\xe5‘ in file [How to Solve]
- [Solved] ParserError: NULL byte detected. This byte cannot be processed in Python‘s native csv library
- [Solved] git review Error: UnicodeDecodeError: ‘gbk‘ codec can‘t decode
- The range of Chinese Unicode encoding and the calculation of the number of Chinese and English words in text
- SyntaxError: Non-UTF-8 code starting with ‘\xe4‘ in file [How to Solve Chinese encoding problem]
- [Solved] SyntaxError: Non-UTF-8 code starting with ‘\xe6‘ in file
- Djangorestframework-simplejwt: ‘str‘ object has no attribute ‘decode‘ [Solved]
- Python 3.7 Error: AttributeError: ‘str‘ object has no attribute ‘decode‘ [How to Solve]
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘
- IndexError: list index out of range [How to Solve]