mysql unsupported operand type(s) for %: 'tuple' and 'tuple'
来源:互联网 发布:淘宝购物的流程 编辑:程序博客网 时间:2024/05/16 01:19
环境:ubuntu14.04,python2.7
这篇文章只是为了记录我碰到的一个mysql相关的小问题
学习爬虫,看到一个项目:https://github.com/airingursb/bilibili-report](https://github.com/airingursb/bilibili-report
看了下代码,就是爬取bili用户信息后保存到mysql中。因为想之后方便提取mysql里的信息,所以将mysql相关的代码修改,放到另一个模块。
其中添加数据的代码如下:
class Ch_mysql(): def __init__(self): self.conn = pymysql.connect(host='127.0.0.1', port=3306, user='user', passwd='passwd', db=database, charset='utf8') def add(self, kwargs): mid = kwargs.get('mid', None) name = kwargs.get('name', None) sex = kwargs.get('sex', None) face = kwargs.get('face', None) coins = kwargs.get('coins', None) regtime = kwargs.get('regtime', None) spacesta = kwargs.get('spacesta', None) birthday = kwargs.get('birthday', None) place = kwargs.get('place', None) description = kwargs.get('description', None) article = kwargs.get('article', None) fans = kwargs.get('fans', None) friend = kwargs.get('friend', None) attention = kwargs.get('attention', None) sign = kwargs.get('sign', None) attentions = kwargs.get('attentions', None) level = kwargs.get('level', None) exp = kwargs.get('exp', None) sql = "INSERT INTO bilibili_user_info VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" try: cur = self.conn.cursor() cur.execute(sql, (mid, mid, name, sex, face, coins, regtime, spacesta, birthday, place, description, article, fans, friend, attention, sign, str(attentions), level, exp)) cur.close() # raise # for test self.conn.commit() # commit之后raise不会回滚了 except Exception, e: print 'db Exception: ', e self.conn.rollback() finally: # cur.close() # self.conn.commit() self.conn.close()
这是改好的代码,之前代码中sql因为用的单引号,所以一直报错:unsupported operand type(s) for %: 'tuple' and 'tuple'
查了些文章说是python的问题,搞不清原因,后来照以前的代码意义对比,将单引号改为双引号后就好了
呃,总之还不清楚为什么这样,聊作记录而已
0 0
- mysql unsupported operand type(s) for %: 'tuple' and 'tuple'
- TypeError: unsupported operand type(s) for +: 'int' and 'str'
- J版bug之_get_host_numa_topolo TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'
- Python初学者错误:TypeError: unsupported operand type(s) for +: 'int' and 'str'
- Python PIP Install throws TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
- tuple
- Tuple
- tuple
- Tuple
- Tuple and ref
- Python list and tuple
- Tuple and Tie
- python list and tuple
- “list” and “tuple”
- python tuple and dict arg
- Python Container Tuple and List
- learning Python-Tuple and files
- Python练习-- list and tuple
- 快速排序(随机化版本)
- Python 中类和实例的通俗讲解
- Magical GCD
- 华为6.0的WRITE_SETTING权限问题
- ScrollView嵌套ListView需要使用的View
- mysql unsupported operand type(s) for %: 'tuple' and 'tuple'
- 前端复习--relative盒子的坍塌
- R语言相关文件保存执行abc
- 《Hadoop基础教程》之初识Hadoop
- js基础:局部变量、全局标量、闭包
- E - Generate a String dp
- web.xml
- 【Java基础知识】继承体系中的成员关系,this,super关键字的使用,数据初始化
- Excel常用功能速查手册