Xiaobin Zhang
Xiaobin Zhang

Reputation: 105

mysql-connector-python raise mysql.connector.errors.InterfaceError: Expected EOF packet

I use mysql-connector-python to fetch data from database. Here is the basic code:

db = mysql.connector.connect(
    host=config.MYSQL_HOST,
    user=config.MYSQL_USER,
    password=config.MYSQL_PASSWORD,
    database=config.MYSQL_DATABASE,
)
cursor = db.cursor(dictionary=True)
cursor.execute('select * from UserOrder')
orders = cursor.fetchall()

order_ids = str((order['id']) for order in orders))
record_sql = 'select * from PriceRecord where order_id in %s'
cursor.execute(record_sql, order_ids)
recrods = cursor.fetchall()

The first sql executed successfully and returns order data, but the second sql raise error like this:

...
    cursor.execute(record_sql, order_ids)
  File "/var/???/order_summary_tool.runfiles/mysql_connector_python_py/lib/mysql/connector/cursor.py", line 577, in execute
    self._handle_result(self._connection.cmd_query(stmt))
  File "/var/???/order_summary_tool.runfiles/mysql_connector_python_py/lib/mysql/connector/connection.py", line 695, in cmd_query
    result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
  File "/var/???/order_summary_tool.runfiles/mysql_connector_python_py/lib/mysql/connector/connection.py", line 594, in _handle_result
    eof = self._handle_eof(self._socket.recv())
  File "/var/???/order_summary_tool.runfiles/mysql_connector_python_py/lib/mysql/connector/connection.py", line 501, in _handle_eof
    raise errors.InterfaceError('Expected EOF packet')
mysql.connector.errors.InterfaceError: Expected EOF packet

It seems the connection is closed with database, I wonder where go wrong.

Another weird thing is that this code works locally, but failed in k8s pod. I tried changed my local mysql-connector-python lib with version of 8.0.23, but it still failed.

Upvotes: 0

Views: 84

Answers (0)

Related Questions