【问题标题】:Why am I getting this MySQL error in pika python, unread result found为什么我在 pika python 中收到此 MySQL 错误,找到未读结果
【发布时间】:2021-04-19 18:58:32
【问题描述】:

在执行加粗的 sql 命令时发现未读结果错误。 python 代码位于 docker 容器中,MySQL db 也是如此。截断代码以突出显示问题所在。

import mysql.connector
from datetime import datetime
import requests
import json
import math
import os
import logging

# Use logging.info() to output info to the console
logging.basicConfig(level=logging.INFO)

# Connecting to the MySQL Docker image
cnx = mysql.connector.connect(user='test', password='test', host='db', database='VisualDB')
logging.info(cnx.is_connected())
# Use mycursor for pointing to tables and making queries<br>
mycursor = cnx.cursor()
userRows = mycursor.execute("SELECT * FROM user;")
cnx.commit()
logging.info(userRows)
sensorRows = mycursor.execute("SELECT * FROM SENSOR;")
cnx.commit()
logging.info(sensorRows)

这是我得到的错误:mysql.connector.errors.InternalError: Unread result found 做了一堆评论来确认这些行是问题所在,我有时也会在cnx().commit
我的图像本身有问题吗? mysql:最新
此外,数据库是使用“db”文件夹中指向 sql 文件的 Dockerfile 创建的

提前感谢您提供的任何建议!

【问题讨论】:

    标签: python mysql docker mysql-connector pika


    【解决方案1】:

    logging.info(userRows)消耗mycursor.execute("SELECT * FROM user;")返回的结果,所以下次调用mycursor.execute会导致上述错误。

    尝试消费结果,即logging.info(list(userRows))

    【讨论】:

      猜你喜欢
      • 2010-12-18
      • 1970-01-01
      • 1970-01-01
      • 2012-09-15
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      相关资源
      最近更新 更多