Where the HTML and database are set to UTF-8 format encoding, inserted into the database is correct, but when read out of error, because the Python str default is ASCII encoding, and Unicode encoding conflict, will report this header error. So how to solve it?
Through the collection of online information, their own attempts, the problem is solved, in the code to add the following sentence can be.
SYSReload(sys)sys. Setdefaultencoding(' UTF8 ')
Http://docs.python.org/howto/unicode.html This is the Python Unicode encoding API documentation, English good students can look, deepen understanding.
Reference: Http://groups.google.com/group/python-cn/browse_thread/thread/f48ef745452740f6?pli=1
Click to open link
--------------------------------------------------------------------------------------------------------------- ---------
The STR and Unicode data types inside the Python2 are confused.
0.
What you need is for the code to be actually coded instead of ASCII.
1.
For code that needs Str->unicode, you can write it in the front
Import Sys
Reload (SYS)
Sys.setdefaultencoding (' utf8′)
Change STR encoding from ASCII to UTF8 (or GB18030)
2.
Python3 distinguishes between Unicode STR and byte arrary, and the default encoding is no longer ASCII
Htmltestrunner solution unicodedecodeerror: ' ASCII ' codec can ' t decode byte 0xe5 in position 108:ordinal not in range (128)