python mysqldb 报错: ProgrammingError: must be real number, not str 解决

代码:

sql = ‘insert into book(book_name,book_desc,origin_price,publish_id,tag_id,book_img) values(%s,%s,%d,%d,%d,%s)‘
insert_data = save_df.values.tolist()
commit_data = tuple([tuple([str(x[0]),str(x[1]),float(x[2]),int(x[3]),int(x[4]),str(x[5])]) for x in insert_data])

# 执行插入语句
cursor.executemany(sql,commit_data)
# 提交插入动作
conn.commit()

执行后报错: ProgrammingError: must be real number, not str

解决:

在sql语句中把 所有的站位符 换成 %s,不用能其他的站位符。

原文地址:https://www.cnblogs.com/ctsch/p/8682846.html

时间: 2024-07-30 05:14:44

python mysqldb 报错: ProgrammingError: must be real number, not str 解决的相关文章

python 编码报错问题 'ascii' codec can't encode characters 解决方法

python在安装时,默认的编码是ascii, 当程序中出现非ascii编码时,python的处理常常会报这样的错 'ascii' codec can't encode characters python没办法处理非ascii编码的, 此时需要自己设置将python的默认编码,一般设置为utf8的编码格式. 查看python的默认编码 print sys.getdefaultencoding() 解决方法一(已通过验证,顺带也解决了我之前字符前一直加u的问题) 在python安装目录下,进入\P

Python递归报错:RuntimeError: maximum recursion depth exceeded in comparison

Python中默认的最大递归深度是989,当尝试递归第990时便出现递归深度超限的错误: RuntimeError: maximum recursion depth exceeded in comparison 简单方法是使用阶乘重现: 1 #! /usr/bin/env Python 2 3 def factorial(n): 4 5 if n == 0 or n == 1: 6 7 return 1 8 9 else: 10 11 return(n * factorial(n - 1)) >

python中引入包的时候报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法?

python中引入包的时候报错:import unittestimport smtplibimport timeimport osimport sysimp.reload(sys)sys.setdefaultencoding('utf-8') AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法: 1.python2中解决方法:reload(sys)sys.setdefaultencoding('utf-8'

安装python模块报错 error: command 'gcc' failed with exit status 1

最近在安装paramiko模块的时候,总是报错:error: command 'gcc' failed with exit status 1,一开始比较挠头.找了蛮多资料,说的大多都是说缺少Python-devel 包,然而并不是! 最后蛮费劲的找到了一遍短小但就是正确的博文:http://blog.csdn.net/fenglifeng1987/article/details/38057193 —————————————————————— 解决方法: 安装:yum install gcc li

运行python代码报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 91: ordinal not in range(128)的解决办法

1.通过搜集网上的资料,自己多次尝试,问题算是解决了,在代码中加上如下几句即可: import sys reload(sys) sys.setdefaultencoding('utf-8') 2.原因就是Python的str默认是ascii编码,和unicode编码冲突,混淆了python2 里边的 str 和 unicode 数据类型. 3.python3 区分了 unicode str 和 byte arrary,并且默认编码不再是 ascii. 运行python代码报错UnicodeDec

win10 64位 python3.6 django1.11 MysqlDB No module named 'MySQLdb' 安装MysqlDB报错 Microsoft Visual C++ 14.0 is required

在python3.6中操作数据库,再按python2.7安装MySQLdb进行数据库连接已经不可用了,我使用的是另外一个方法:PyMySQL,安装好之后还是不能直接连接MySQL的,启动项目后报No module named 'MySQLdb' 解决方案: 在项目的__init__()文件中添加如下代码: import pymysql pymysql.install_as_MySQLdb() 这时再次启动项目正常 win10 64位 python3.6 django1.11 MysqlDB No

python执行报错 configparser.NoSectionError: No section: 'section_1'

场景:请求获取验证码模块regVC.py读取配置文件config.ini时,regVC.py模块单独执行正常,但通过run_all.py模块批量执行时报错,找不到section 解决办法:配置文件路径需写绝对路径 config.ini文件如下: regVC.py模块代码如下: 1 import requests 2 import configparser 3 import unittest 4 from Case.readexcel import ExcelData 5 import json

python webdriver 报错WebDriverException: Message: can't access dead object的原因(pycharm中)

PyCharm中运行firefox webdriver访问邮箱添加通讯录的时候报错-WebDriverException: Message: can't access dead object 调了半天,发现是因为在登录操作后没有从frame中切换出来导致的,因为在登录的时候需要先切换到frame中,登录之后要切换出来才能继续其他操作. 下面是我运行的代码,driver.switch_to.default_content()这一行被我注释掉了,结果就报这个错 代码:driver=webdriver

python执行报错“UnicodeDecodeError: 'gbk' codec can't decode byte 0xa1 in position 110: illegal multibyte sequence”

执行如下程序报错 import pytest @pytest.fixture() def user(): print("获取用户名") a = "zt" return a def test_1(user): assert user == "zt" if __name__ == "__main__": pytest.main(["-s","test_fixture1.py"]) Testi