weixin_48662683 2021-12-08 03:28 采纳率: 100%
浏览 1399
已结题

TypeError: not all arguments converted during string formatting 一直出来这个

一直出现那个错误

def close_conn(conn, cursor):
    if cursor:
        cursor.close()
    if conn:
        conn.close()

def update_details(url_today):
    cursor = None
    conn = None
    try:
        detail_data = get_today(url_today)
        conn, cursor = get_conn()
        sql = "insert into details(update_time,province,city,confirm,confirm_add,heal,dead) values(%s,%s,%s,%s,%s,%s,%s)"
        sql_query = 'select %s=(select update_time from details order by id desc limit 1)'
        cursor.execute(sql_query, detail_data[0][0])
        if not cursor.fetchone()[0]:
            print(f"{time.asctime()}开始更新最新数据")
            for item in detail_data:
                cursor.execute(sql, item)
            conn.commit()  # 提交事务 update delete insert操作
            print(f"{time.asctime()}更新最新数据完毕")
        else:
            print(f"{time.asctime()}已是最新数据!")
    except:
        traceback.print_exc()
    finally:
        close_conn(conn, cursor)

def insert_history(url_history):
    cursor = None
    conn = None
    try:
        dic = get_history(url_history)
        print(f'{time.asctime()}开始插入历史数据')
        conn, cursor = get_conn()
        sql = "insert into history values(%s,%s,%s,%s,%s,%s,%s,%s,%s)"
        for key, value in dic.items():
            cursor.execute(sql, [key, value.get("confirm"), value.get("confirm_add"), value.get("suspect"),
                                 value.get("suspect_add"), value.get("heal"), value.get("heal_add"),
                                 value.get("dead"), value.get("dead_add")])
        conn.commit()
        print(f"{time.asctime()}插入历史数据完毕")
    except:
        traceback.print_exc()
    finally:
        close_conn(conn, cursor)

def update_history(url_history):
    cursor = None
    conn = None
    try:
        dic = get_history(url_history)
        print(f"{time.asctime()}开始更新历史数据")
        conn, cursor = get_conn()
        sql = "insert into history values(%s,%s,%s,%s,%s,%s,%s,%s,%s)"
        sql_query = "select confirm from" \
                    "history where ds=&s"
        for key, value in dic.items():
            if not cursor.execute(sql_query, key):
                cursor.execute(sql, [key, value.get("confirm"), value.get("confirm_add"), value.get("suspect"),
                                     value.get("suspect_add"), value.get("heal"), value.get("heal_add"),
                                     value.get("dead"), value.get("dead_add")])
        conn.commit()
        print(f"{time.asctime()}历史数据更新完毕")
    except:
        traceback.print_exc()
    finally:
        close_conn(conn, cursor)

def update_world(url_world):
    cursor = None
    conn = None
    try:
        list = get_world(url_world)
        print(f"{time.asctime()}开始更新历史数据")
        conn, cursor = get_conn()
        sql = "TRUNCATE TABLE world"
        cursor.execute(sql)
        sql = "insert into world values(%s,%s)"
        for i in list:
            cursor.execute(sql,[(i[0]),(i[1])])
        sqll ="SELECT confirm FROM history ORDER BY ds DESC LIMIT 1"
        cursor.execute(sqll)
        nu = cursor.fetchall()
        dat =int(nu[0][0])
        cursor.execute(sql,[('中国'),(dat)])
        conn.commit()
        print(f"{time.asctime()}历史数据更新完毕")
    except:
        traceback.print_exc()
    finally:
        close_conn(conn, cursor)

if __name__ == '__main__':
   print(get_history(url_history))
   print(get_today(url_today))
   insert_history(url_history)
   print(get_world(url_world))
   update_details(url_today)
   update_history(url_history)
   update_world(url_world)


TypeError: not all arguments converted during string formatting
怀疑是数据库字符设置的不合适
结课求帮助

  • 写回答

1条回答 默认 最新

  • CSDN专家-文盲老顾 2021-12-08 05:37
    关注

    img

    &s??

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月16日
  • 已采纳回答 12月8日
  • 创建了问题 12月8日

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容