For the Chinese coding problem, there will always be a variety of disgusting errors, do not know how to solve, first of all, you should focus on the coding problem from the beginning, try to ensure that all coding methods are consistent
Use Python+web.py+mysql to write the program, first of all to ensure that the following parts of the code are the drop
The main parts include the following:
1:python wrote the program, unified with Utf-8, and re-loaded into Utf-8
2:web.py templates, which are HTML programs
The Unified save format is Utf-8, and the HTML declaration <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
3:mysql the database, the database uses the UTF-8 (including building the database and building the table, the encoding format is used UTF8)
But in the end there will be such a problem, the error message is as follows:
[2015-06-02 10:35:38] [INFO] Self.pool <dbutils.pooleddb.pooleddb instance at 0x028e7e18>
[2015-06-02 10:35:38] [INFO] conn:
[2015-06-02 10:35:38] [INFO] <dbutils.pooleddb.pooleddedicateddbconnection instance at 0x02ada580>
[2015-06-02 10:35:38] [info] cursor:
[2015-06-02 10:35:38] [info] <mysqldb.cursors.cursor Object at 0x029eed10>,
[2015-06-02 10:35:38] [ERROR] Db_execute Error:traceback (most recent call last):
File "E : \code\mid-project-2015-6-2\dailypaper\model.py ", line 131, in Execute
cursor.execute (SQL)
File" C:\Python26\ lib\site-packages\dbutils-1.1-py2.6.egg\dbutils\steadydb.py ", line 552, in tough_method
result = Method (*args, * * Kwargs) # Try to execute
File ' C:\Python26\lib\site-packages\MySQLdb\cursors.py ', line 149, in execute
query = que Ry.encode (CharSet)
Unicodeencodeerror: ' latin-1 ' codec can ' t encode characters in position 86-100:ordinal not in range (+)
Then can see is cursors.py inside of query = Query.encode (charset), then should be the reason of this charset, directly to change CharSet to ' Utf-8 ' on the line, query = Query.encode (' Utf-8 ')
Then you can insert, and you can select the correct value, and then from the Web page can also be seen!!!
Web.py+mysql Insert Chinese hint query = Query.encode (charset) Unicodeencodeerror: ' latin-1 ' codec can ' t encode characters in position 8 6-100