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. [BZOJ1572] WorkScheduling

    中文题目:工作安排 原文题目:Work Scheduling 传送门 本题可以采用贪心 算法一:按工作时间排序,如果工作能按时完成的工作就按时完成,如果工作不能按时完成就把之前价值最小的工作和当前作比 ...

  2. Configuring IPMI under Linux using ipmitool

    http://www.thomas-krenn.com/en/wiki/Configuring_IPMI_under_Linux_using_ipmitool Configuring IPMI und ...

  3. CodeForce-1196D1-RGB Substring (easy version)

    原题链接 题目大意: 给出一串由'R', 'G', 'B'组成的长度为n的字符串,在里面选出一个长度为k的子串,要求在改变最少字符的情况下同时也是"RGBRGBRGB…"的子串. ...

  4. 初学Selenium遇上的问题

    1.IWebDriver driver = new InternetExplorerDriver();运行时报关于protecte model的错误 解决办法就是用如下代码设置IEDriverOpit ...

  5. 01、python的基础-->while循环应用

    1.简单的输出小程序 name = input('请输入你的名字:') age = input('请输入你的年龄:') print('我的名字叫'+name,'我今年'+ age + '岁') 2.w ...

  6. Pikachu漏洞练习平台实验——CSRF(三)

    概述 CSRF 是 Cross Site Request Forgery 的 简称,中文名为跨域请求伪造 在CSRF的攻击场景中,攻击者会伪造一个请求(一般是一个链接) 然后欺骗目标用户进行点击,用户 ...

  7. 转 zookeeper,dubbo和Nginx的区别

    Nginx是著名的反向代理服务器,也被广泛的作为负载均衡服务器 ZooKeeper是分布式协调服务框架,有时也被用来做负载均衡 那么他们的区别是什么?如何选择呢? 下面从实际场景看下他们的关系 Ngi ...

  8. 注册服务到服务中心(Consul)

    注册服务到服务中心(Consul) 添加POM文件中的依赖 在POM文件添加如下依赖: <dependency> <groupId>org.springframework.bo ...

  9. js数据处理-----数据拷贝

    一.理解深拷贝与浅拷贝 如下代码,把 a  的值赋给  b ,修改 b 的值会直接修改到  a 的值,这叫浅拷贝.(其实他们修改的是同一个对象) var a = [1,2,3,4,5]; var b ...

  10. python基础--选择排序

    1.首先用一张图来描述选择排序的具体过程 2.废话不多说,上代码 # 1.定义函数:选择排序 def choose_sort(list): list_len = len(list) for i in ...