Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在mysql数据库中存储html数据?_Python_Html_Mysql_Sql - Fatal编程技术网

Python 如何在mysql数据库中存储html数据?

Python 如何在mysql数据库中存储html数据?,python,html,mysql,sql,Python,Html,Mysql,Sql,我有一个类似python的sql cur.execute("INSERT INTO products_details( title, description, price, currency, sku, brand, colors, sizes, actual_url, meta_title, meta_keywords, meta_description, sizefitcontainer, designercontainer, wearwith, colorthumb, colorbig,

我有一个类似python的sql

cur.execute("INSERT INTO products_details(
title,
description,
price,
currency,
sku,
brand,
colors,
sizes,
actual_url,
meta_title,
meta_keywords,
meta_description,
sizefitcontainer,
designercontainer,
wearwith,
colorthumb,
colorbig,
colormedium,
discount_price,
cat_name) 
VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')  ",  (
context['product_title'],
context['product_description'],
context['price'],
context['currency'],
context['productCode'],
context['brand_name'],
context['colors'],
context['sizes'],
context['actual_url'],
context['title'],
context['meta_keywords'],
context['meta_description'],
context['sizefitcontainer'],
context['designercontainer'],
context['wearwith'],
context['colorthumb'],
context['colorbig'],
context['colormedium'],
context['discount_price'],
context['cat_name']))
在上面的查询中,有两个字段
designercontainer和sizefitcontainer
,我在其中传递一些html数据以存储在数据库中。 但每次我都会出错

(<class '_mysql_exceptions.ProgrammingError'>, ProgrammingError(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 'Cosmic Leggings'',''These cropped KORAL ACTIVEWEAR leggings have iridescent cont' at line 1"), <traceback object at 0x2bc2638>).

您应该在问题中包括产品的结构和详细信息


从错误判断,您没有正确引用要存储的HTML字符串。

您需要将数据作为第二个参数传递为
.execute()

那就好像

sql = '''insert into headline (column,column1) 
                   values ("%s","%s","%s","%s","%s");'''
cursor.execute(sql,(值,值1))

这里您没有正确引用要存储到数据库中的html字符串

您可以使用
conn.escape\u string()

看一看

sql = '''insert into headline (column,column1) 
                   values ("%s","%s","%s","%s","%s");'''