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, ‘1‘, ‘1‘)
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异常解决

The format string is not really a normal Python format string. You must always use %s for all fields.

%d format: a number is required, not str。的更多相关文章

  1. python中MySQL模块TypeError: %d format: a number is required, not str异常解决

    转载自:http://www.codeif.com/topic/896 python代码: attr_sql = "INSERT INTO `ym_attribute` (`attr_nam ...

  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. python问题:TypeError: a bytes-like object is required, not 'str'

    源程序: import socket target_host = "www.baidu.com" # 127.0.0.1 target_port = 80 # 建立一个socket ...

  5. python3 TypeError: a bytes-like object is required, not 'str'

    在学习<Python web开发学习实录>时, 例11-1: # !/usr/bin/env python # coding=utf-8 import socket sock = sock ...

  6. 【爬坑】Python 3.6 在 Socket 编程时出现类型错误 TypeError: a bytes-like object is required, not 'str'

    1. 问题描述 Python 3.6 在 Socket 编程时出现错误如下 Traceback (most recent call last): File "F:/share/IdeaPro ...

  7. TCP客户端和服务器间传输数据遇到的TypeError: a bytes-like object is required, not 'str'问题

    使用python实现python核心编程3第472页和474页的TCP时间戳服务器和客户端服务器间数据传输编程时遇到TypeError: a bytes-like object is required ...

  8. linux下运行python3出现TypeError: a bytes-like object is required, not 'str'

    目标:用python将中文存入csv,且中文正常显示. 环境:linux,python3 百度N久,方法都不行或是比较复杂. 以上代码用python3运行后,出现TypeError: a bytes- ...

  9. sbt package报错:a bytes-like object is required, not 'str'

    Traceback (most recent call last): File , in <module> s.sendall(content) TypeError: a bytes-li ...

随机推荐

  1. python类与对象练习题扑克牌

    #定义一个扑克类,属性是颜色,数字.#定义一个手类,属性是扑克牌得颜色数字#定义一个人类,属性是左手,右手.类里定义一些方法,比如交换,展示 class Poker : def __init__(se ...

  2. ANSI转义代码(ANSI escape code)

    ANSI escape code - Wikipedia linux 输出绿色的✓TRUE,红色的✗FALSE : echo -e "\x1B[1;32m✓TRUE \x1B[0mXXX&q ...

  3. kubernetes原理

    kubernetes 核心组件 etcd:保存整个集群的状态 apiserver:提供资源操作的唯一入口,并提供认证.授权.访问控制.api注册和发现等机制 controller manager:负责 ...

  4. 【Unity3D NGUI】----UI尺寸和位置的调整

    1 尺寸与位置 通过UIWidget类获取,该类是所有UI元素的基类 在unity中创建一个sprite,如下图所示 这里面这个sprite的大小受几个属性的影响,首先是属性面板里的Size,对应的U ...

  5. upc组队赛15 Made In Heaven【第K短路 A*】

    Made In Heaven 题目描述 One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with ...

  6. git使用记录七:对工作区和暂存区的一些操作场景

    比较暂存区和HEAD所含文件的差异? 操作场景如下: 修改readme.md 文档 vi readme.md 加入到暂存区域 git add readme.md 使用git diff -cached ...

  7. PHP pthread多线程

    class test extends Thread { public $arg; public function __construct($arg){ $this->arg = $arg; } ...

  8. fusionCharts图表在客户端导出图片

    前提:要具备三个文件:FusionCharts.js / FusionChartsExportComponent.js / FCExporter.swf 1.引用 js 文件 <script t ...

  9. MYSQL 查询脚本优化

    业务需要,优化一段多表查询脚本. 总结下来,采取以下步骤. 分析语句 分析语句,了解逻辑,是否可以先优化逻辑. 查询语句的查询范围,是否是全表查询,如果是,尽量优化为按索引查询. 查看语句数量,是否有 ...

  10. 第八组Postmortem事后分析

    第八组Postmortem事后分析 一.团队成员总结的改进和教训 隆晋威:Beta阶段完善架构设计,分工更加明确,文档更丰富,交流带来开销减少.Alpha技术选型不固定,分工混乱,没有方便的测试引擎, ...