Python 警告:您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,了解要使用的正确语法

Python 警告:您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,了解要使用的正确语法,python,mysql,xml,Python,Mysql,Xml,我正在将解析器xml编码到mysql 错误的全名: 1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHA3871376-ABZ-1', '\xd0\x91\xd1\x80\xd0\xbe\xd0\xbd\xd0\xb7\xd0\xbe\xd0\xb2\xd0\x

我正在将解析器xml编码到mysql

错误的全名:

1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHA3871376-ABZ-1', '\xd0\x91\xd1\x80\xd0\xbe\xd0\xbd\xd0\xb7\xd0\xbe\xd0\xb2\xd0\xbe\xd0\xb5 \xd0\xbc\xd0\xb5\xd1\x82\xd0\xb0\xd0\xbb\xd0\xbb\xd0\xb8\xd1\x87\xd0\xb5\xd1\x81\xd0\xba\xd0\xbe\xd0\xb5 \xd0\xba\xd0\xbe\xd0\xbb\xd1\x8c\xd1\x86\xd0\xbe ' at line 1")
我有一个xml文件

<model>CHA3871376-ABZ-3</model> 
怎么了?

不要使用字符串插值来构建SQL;您将引入错误,并为SQL注入攻击敞开大门

改用SQL参数,并让数据库适配器为您转义值:

sqlfillOffers = (
    "INSERT INTO offers (offer_id, url, price, currency_id, typePrefix, vendor, model, description) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, )"
)

cursor.execute(
    sqlfilOffers,
    (offer_id, offer_url, offer_price, offer_CurrId, offer_typePrefix, offer_vendor, offer_model, offer_description)
)

打印sqlfillOffers
并显示输出。我认为您不需要分号
您的代码几乎没有问题;但首先,如何获得
提供描述
?@thefourtheye:分号仅在支持多个语句的客户端中执行sql时才需要。您发送的查询在最后一个字段中嵌入了
字符,这会导致语法错误这并不能解决他的实际问题;与编码相关。@Burnkhalid:如果数据库连接和数据库配置为unicode,则不会。@Burnkhalid:无论哪种方式,使用unicode值的字符串插值都会使情况变得更糟,在这种情况下,答案仍然是使用SQL参数。
sqlfillOffers = (
    "INSERT INTO offers (offer_id, url, price, currency_id, typePrefix, vendor, model, description) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, )"
)

cursor.execute(
    sqlfilOffers,
    (offer_id, offer_url, offer_price, offer_CurrId, offer_typePrefix, offer_vendor, offer_model, offer_description)
)