python mysql 插入数据报错 Failed processing format-parameters; 'int' object is not iterable
2017-08-25 12:32
1146 查看
搞了半天才找到问题。一直报错 Failed processing format-parameters; 'int' object is not iterable
原因是用这种方式插入数据必须是数组形式才可以,改为如下:
就可以了。
更新数据报错:1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s where href = %s' at line 1 update exception
此问题也是val需要是数组,改为数组就正常了如下:
改为:
希望能帮助大家少走弯路。
data = (0, 'this is title', 'this is abstract', 'image-url', 'views', 'time', 'http:\\www.baidu.com', '这里是评论') sql = "insert into table_name(id ,title,abstract,image,views,time,href,comments) values(%s,%s,%s,%s,%s,%s,%s,%s)" try: cursor.executemany(sql, data) except Exception as e: print(str(e) + 'insert exception') conn.commit()
原因是用这种方式插入数据必须是数组形式才可以,改为如下:
data = [(0, 'this is title', 'this is abstract', 'image-url', 'views', 'time', 'http:\\www.baidu.com', '这里是评论')]
就可以了。
更新数据报错:1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s where href = %s' at line 1 update exception
此问题也是val需要是数组,改为数组就正常了如下:
cursor = conn.cursor() sql = "update ecs_news_qczj set article=%s where href = %s" val = ('123467',hrefu) try: cursor.executemany(sql,val) except Exception as e: print(str(e) + ' update exception') conn.commit()
改为:
val = [('123467',hrefu)]
希望能帮助大家少走弯路。
相关文章推荐
- Python错误代码分析:莫名的[TypeError: 'int' object is not iterable]
- python TypeError: 'int' object is not iterable
- python 'float'object is not iterable
- [置顶] python中报错:'int' object is not callable error occur的解决方案
- TypeError:a bytes-like object is requeired ,not 'int'(使用python3编写出现的错误)
- Python:TypeError: 'int' object is not callable
- 【Python】Error:'int' object is not callable
- usecols = list(usecols) TypeError: 'int' object is not iterable
- Python:TypeError: 'int' object is not callable
- python TypeError: 'builtin_function_or_method' object is not iterable keys
- 【Python】Error:'int' object is not callable
- Python: TypeError: 'int' object is not callable
- 【Python】python "TypeError: 'NoneType' object is not iterable"错误分析
- Python出现TypeError: 'NoneType' object is not iterable
- Python问题:'Nonetype' object is not iterable
- Python 出现错误TypeError: ‘NoneType’ object is not iterable解决办法
- python mysql插入数据报错:TypeError: %d format: a number is required, not str
- python object is not iterable
- python TypeError: 'builtin_function_or_method' object is not iterable keys
- python3.5 模拟UDP客户端发送数据报文,报错:TypeError: a bytes-like object is required, not 'str'