我想在mysql表中插入unicode文本,为此我编写了下面的代码
我用的是烧瓶框架
import MySQLdb as ms
db = ms.connect("localhost","username","password","dbname")
cursor = db.cursor()
my_text = "का" #this is marathi lang word
enc = my_text.encode('utf-8') #after encoding still it shows me marathi word
db_insert = "INSERT INTO TEXT(text) VALUES '{0}'"
cursor.execute(db_insert,(enc))
db.commit()
它给出了以下错误
TypeError: not all arguments converted during string formatting on line cursor.execute()
如何删除此错误?在
您需要将一个序列(一个
list
或tuple
)传递给params
incursor.execute
语句:您可以在documentation中阅读更多:
或者,您甚至可以使用named parameters:
^{pr2}$把这个放在源代码的开头:
不要对已经编码的内容进行编码-删除
my_text.encode('utf-8')
在连接调用中使用
charset="utf8", use_unicode=True
。在表/列中的}。
CHARACTER SET
必须是utf8
或{latin1
是否会使不正常工作。在Python checklist
相关问题 更多 >
编程相关推荐