mysql和sqlite3多次查询问题,搞了几次没搞定

liwan123 2020-03-17 10:03:13
两个mysql表:table1,table2,两个表的id值相同,目的是从mysql表table1中查出数据,然后在sqlite3的表table3中查出和mysql的table1具有相同biaoti 、company 、kanwu值的字段filename,再用filename的值去更新mysql表table2中downpath值,现在第一步已经完成,最后一步更新table2的downpath值提示错误,很奇怪,TypeError: not all arguments converted during string formatting

import time
import urllib.request
import urllib.parse
import sqlite3
import pymysql

if __name__ == "__main__":
connmysql = pymysql.connect(user='root', password='123456', database='empiredd', charset='utf8')
cursormysql = connmysql.cursor()
query = 'select id, title , company, qikanname from table1'
cursormysql.execute(query)
for (id, title, company, qikanname) in cursormysql:
print(id, title, company, qikanname)
conn = sqlite3.connect(r"E:\网站\SpiderResult.db3")
cursor = conn.cursor()
sql = "select filename from table3 where biaoti = ? and company = ? and kanwu = ?"
cursor.execute(sql, (title, company, qikanname))
values = cursor.fetchone()
print(values[0])
print(id)
cursormysql.execute('update table2 set downpath = ? where id = ?', (values[0], id))
connmysql.commit()
cursor.close()
conn.close()
cursormysql.close()
connmysql.close()

错误提示是cursormysql.execute('update table2 set downpath = ? where id = ?', (values[0], id)),很奇怪
...全文
282 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
冰风漫天 2020-03-18
  • 打赏
  • 举报
回复
按道理不应该报错,你把?换成%s看看,还有把完整的错误信息再发一下
陈年椰子 2020-03-18
  • 打赏
  • 举报
回复
cursormysql.execute('update table2 set downpath = ? where id = ?', (values[0], id)) 改成 cursormysql.execute('update table2 set downpath = ? where id = ?', (values[0][0], id)) 因为 values[0] 是 结果集的第一条记录。 values[0][0] 才是第一条记录的 filename 字段的值。
liwan123 2020-03-17
  • 打赏
  • 举报
回复
print(values[0]) 的结果是str类型,值为wxrokl4xnp2.pdf print(id)的结果是60,这两个值都是正确的,
liwan123 2020-03-17
  • 打赏
  • 举报
回复
网站好像自动转码了,源代码如下: import time import urllib.request import urllib.parse import sqlite3 import pymysql if __name__ == "__main__": connmysql = pymysql.connect(user='root', password='123456', database='empiredd', charset='utf8') cursormysql = connmysql.cursor() query = 'select id, title , company, qikanname from table1' cursormysql.execute(query) for (id, title, company, qikanname) in cursormysql: print(id, title, company, qikanname) conn = sqlite3.connect(r"E:\网站\SpiderResult.db3") cursor = conn.cursor() sql = "select filename from table3 where biaoti = ? and company = ? and kanwu = ?" cursor.execute(sql, (title, company, qikanname)) values = cursor.fetchone() print(values[0]) print(id) cursormysql.execute('update table2 set downpath = ? where id = ?', (values[0], id)) connmysql.commit() cursor.close() conn.close() cursormysql.close() connmysql.close()

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧