八成是丢失连接了

while  1:
    try:
        self.conn.ping(reconnect=True)
        self.cur.execute(sql,tuple(item.values()))
        self.conn.commit()
        break
    except Exception as e:
        print("error save item  ",e)
        self.r.lpush("save_article_error",str(item))
        time.sleep(5)
        self.get_redisconn()

在每次执行sql语句前先执行 conn.ping(reconnect=True),可以保证conn丢失时自动重连。

相关文章:

  • 2021-06-05
  • 2021-08-29
  • 2021-11-05
  • 2021-04-12
  • 2022-12-23
  • 2021-11-19
  • 2021-06-06
  • 2021-04-27
猜你喜欢
  • 2021-10-02
  • 2022-12-23
  • 2021-08-17
  • 2022-01-14
  • 2022-01-10
  • 2021-07-14
  • 2021-09-17
相关资源
相似解决方案