Home » Python » pytho

pytho

bug1
UnicodeEncodeError: 'ascii'codec can't encode characters in position 0-1 not in: ordinal range (128) 

this is the reason for the Python encoding format. Add the following statement

after the import package

sys.setdefaultencoding ('utf8')


sets the default encoding format of utf8


BUG2
UnicodeEncodeError: 'latin-1'codec can't encode character u'u79d2' in position 5 not in: ordinal range (256) 

MySQLdb normally attempts to convert all of the content into Latin1 character set processing, so see the solution below.

Solution:


db = MySQLdb.connect (host= "localhost" , user "root"  = , passwd = , DB = ""  "testdb" , use_unicode=True, charset= "utf8" ) < / span>

Bug3
_mysql_exceptions.OperationalError:  (1136, Column, count, doesn't, match, value, count, at, row, 1) 
solution: the column name of the database table is consistent with the field name of the program inserted into the database..



copyright notice: This article is original article for blogger. Without permission from blogger,.

must not be reprinted

Latest