转载自:http://www.codeif.com/topic/896

python代码:

attr_sql = "INSERT INTO `ym_attribute` (`attr_name`, `type_id`, `attr_value`, `attr_show`, `attr_sort`) VALUES(%s, %s, %s, %s, %s)"
param = (product_attr, type_id, product_attr_v, '', '')
n = cursor.execute(attr_sql, param)

python执行上面的语句会报下面的错误:%d format: a number is required, not str。

最终在stackoverflow查到了问题的解决方案 
http://stackoverflow.com/questions/5785154/python-mysqldb-issues

答案为:The format string is not really a normal Python format string. You must always use %s for all fields. 也就是MySQLdb的字符串格式化不是标准的python的字符串格式化,应当一直使用%s用于字符串格式化

python中MySQL模块TypeError: %d format: a number is required, not str异常解决的更多相关文章

  1. %d format: a number is required, not str。

    python代码: attr_sql = "INSERT INTO `ym_attribute` (`attr_name`, `type_id`, `attr_value`, `attr_s ...

  2. 解决python查询报%d format: a number is required, not str问题

    文章链接:https://blog.csdn.net/u011878172/article/details/72599120 [问题描述] 1.在一条查询语句中,查询条件既包含了整形又包含了字符串型, ...

  3. pymysql连接提示format: a number is required, not str

    最近想随手写一个简单的员工管理系统,第一次使用python连接数据库,在这个过程中就遇到了一些问题,遂记录 遇到问题习惯性百度一下,很多教程都不适合新手,有些还不知道是不是瞎写的,所以我觉得有必要自己 ...

  4. yum安装memcache,mongo扩展以及python的mysql模块安装

    //启动memcached/usr/local/memcached/bin/memcached -d -c 10240 -m 1024 -p 11211 -u root/usr/local/memca ...

  5. Python中time模块详解

    Python中time模块详解 在平常的代码中,我们常常需要与时间打交道.在Python中,与时间处理有关的模块就包括:time,datetime以及calendar.这篇文章,主要讲解time模块. ...

  6. python中socket模块详解

    socket模块简介 网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket.socket通常被叫做"套接字",用于描述IP地址和端口,是一个通信 ...

  7. Python中logging模块的基本用法

    在 PyCon 2018 上,Mario Corchero 介绍了在开发过程中如何更方便轻松地记录日志的流程. 整个演讲的内容包括: 为什么日志记录非常重要 日志记录的流程是怎样的 怎样来进行日志记录 ...

  8. python中MySQLdb模块用法实例

    篇文章主要介绍了python中MySQLdb模块用法,以实例形式详细讲述了MySQLdb模块针对MySQL数据库的各种常见操作方法,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了python中 ...

  9. python中hashlib模块用法示例

    python中hashlib模块用法示例 我们以前介绍过一篇Python加密的文章:Python 加密的实例详解.今天我们看看python中hashlib模块用法示例,具体如下. hashlib ha ...

随机推荐

  1. 在使用Arduino中遇到的问题(无法使用中文注释、程序无法下载)

    在使用Arduino中遇到的问题: 在用arduino给蓝牙模块供电时,下载程序是下不进去的.即使显示下进去了,其实也是没下进去. 解决方法:拔掉蓝牙模块再下程序,或给蓝牙供电的线上加上一个开关. 在 ...

  2. 【转】jmeter入门教程- Jmeter教程及技巧汇总

    https://blog.csdn.net/zouxiongqqq/article/details/72843500

  3. css :not 选择器

    :not 选择器是css3里面的 :not([class]){color:red;}  // 没有class属性的元素都设置为红色 p:not([class]){color:red;} // 没有cl ...

  4. HDU 6335.Problem D. Nothing is Impossible-思维题 (2018 Multi-University Training Contest 4 1004)

    6335.Problem D. Nothing is Impossible 题意:给你n道题目,m个人,每题有x个正确选项,y个错误选项,问你做对题数量最多的人做对了多少道题目. 如果一道题有y个错误 ...

  5. Codeforces 651 B. Beautiful Paintings

    B. Beautiful Paintings   time limit per test 1 second memory limit per test 256 megabytes input stan ...

  6. C# 用程序读写另一个控制台程序

    一. using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { Console.W ...

  7. 19、Flask实战第19天:CSRF攻击与防御

    CSRF攻击原理 网站是通过cookie来实现登录功能的.而cookie只要存在浏览器中,那么浏览器在访问这个cookie的服务器的时候,就会自动的携带cookie信息到服务器上去.那么这时候就存在一 ...

  8. Gitlab运维

    安装Gitlab 新建 /etc/yum.repos.d/gitlab-ce.repo [gitlab-ce] name=gitlab-ce baseurl=http://mirrors.tuna.t ...

  9. 【二分图】【最大匹配】【匈牙利算法】CODEVS 2776 寻找代表元

    裸的匈牙利,存模板. #include<cstdio> #include<vector> #include<cstring> using namespace std ...

  10. yii2.0权限控制 ACF权限

    ACF是一种通过yii\filters\AccessControl类来实现的简单授权 有两种角色 ?:未经认证的游客用户 @:已认证的用户 ACF可同过对角色设置权限控制访问 1)记得引入yii\fi ...