首页 > 数据库> > 《错误记录——SQL上传时错误。错误描述pymysql.err.OperationalError: (1241, ‘Operand should contain 1 column(s)‘)
《错误记录——SQL上传时错误。错误描述pymysql.err.OperationalError: (1241, ‘Operand should contain 1 column(s)‘)
作者:互联网
本次错误2021年12月24日出现,出现在爬虫上传本地数据库中。错误同样无大问题。
问题,描述:
Traceback (most recent call last):
File "E:\python\lib\site-packages\pymysql\connections.py", line 1156, in read
first_packet = self.connection._read_packet()
File "E:\python\lib\site-packages\pymysql\connections.py", line 725, in _read_packet
packet.raise_for_error()
File "E:\python\lib\site-packages\pymysql\protocol.py", line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File "E:\python\lib\site-packages\pymysql\err.py", line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.OperationalError: (1241, 'Operand should contain 1 column(s)')
出现原因:
在数据与上传值对应 并无问题的情况下,
数据库中不支持Python中列表格式上传,上传值中出现列表时会出现此种错误
列如:
def sjk(id, biaoti, lianjie, shijian, jianjie, leibie, leibie_wangzhan, biaoqian, tupian, beixuan, tupian_xuwei,
wangzhi_xuwei, shijian_xuwei, redu_xuwei, laiyuan, laiyuantu, laiyuanurl, shijianchuo):
# try
# 改变备选图片列表中的逗号值
conn = pymysql.connect(password="123456", user="root", database="redianzixun", charset="utf8mb4")
cursor = conn.cursor()
value = (
id, biaoti, lianjie, shijian, jianjie, leibie, leibie_wangzhan, biaoqian, tupian, beixuan1, tupian_xuwei,
wangzhi_xuwei,
shijian_xuwei, redu_xuwei, laiyuan, laiyuantu, laiyuanurl, shijianchuo)
panding = """SELECT * from zixun_bendi where FIND_IN_SET(%s,id)"""
cursor.execute(panding, id)
result = cursor.fetchall()
if len(result) == 0:
sql = """INSERT IGNORE INTO zixun_bendi (id,biaoti,lianjie,shijian,jianjie,leibie,leibie_wangzhan,biaoqian,tupian,beixuan,tupian_xuwei,wangzhan_xuwei,shijian_xuwei,redu_xuwei,laiyuan,laiyuantu,laiyuanurl,shijianchuo ) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"""
cursor.execute(sql, value)
其中“beixuan”与”leibie_wangzhan”都是列表格式,
解决方法可以是对这两个列表进行处理转化为字符串格式
例如:
beixuan = ",".join([str(x) for x in beixuan])
leibie_wangzhan = ",".join([str(x) for x in leibie_wangzhan])
标签:xuwei,错误,err,column,pymysql,tupian,leibie,shijian,wangzhan 来源: https://blog.csdn.net/Deathless_Dawn/article/details/122121503