MySQLdb problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • liupei

    #1

    MySQLdb problem

    I am use mod_python3.2.8 ,MySQL-python-1.2.1_p2,mysql5 .0.20,centOS
    when I run the script below(I have also saved this script in utf-8):
    #coding: utf-8
    from MySQLdb import connect
    connection=conn ect(user='root' ,passwd='',host ='localhost',db ='test')
    cursor = connection.curs or()
    cursor.execute( "INSERT INTO `fee` ( `affair` ) VALUES ('测试')")
    #'测试' is a chinese word means test

    it raise error:
    Traceback (most recent call last):
    File "test.py", line 8, in ?
    cursor.execute( "INSERT INTO `fee` ( `affair` ) VALUES ('测试')")
    File "/opt/python/lib/python2.4/site-packages/MySQLdb/cursors.py",
    line 146, in execute
    query = query.encode(ch arset)
    UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xe6 in position
    40: ordinal not in range(128)

Working...