MySQL Connector/Python InterfaceError: “Failed par

2019-09-07 07:28发布

问题:

As far as I can tell, I have installed the MySQL Connector/Python (v1.2.3) module without a problem. This is on CentOS 5.4 using Python 2.7.7 (Anaconda distribution, although the same happens on a vanilla installation). I'm able to import it and initialize a connection with a MySQL server (v4.1.20). This server is accessed over the LAN, not locally. The is_connected() method asserts that I'm properly connected

>>> import mysql.connector 
>>> cnx = mysql.connector.connect(<MySQL database information here>) 
>>> cursor = cnx.cursor()
>>> cnx.is_connected() 
True 

However, whenever I attempt to execute any SQL query, either directly via a cursor command (e.g. cursor.execute("SELECT DATABASE();")) or indirectly via a mysql.connector method (e.g., get_database()), I obtain the same error, as follows:

>>> cnx.get_database() 
Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
File "/home/bgrande/software/genesis/anaconda-2.0.1/lib/python2.7/site-packages/mysql/connector/connection.py", line 1200, in get_database 
return self._info_query("SELECT DATABASE()")[0] 
File "/home/bgrande/software/genesis/anaconda-2.0.1/lib/python2.7/site-packages/mysql/connector/connection.py", line 1434, in _info_query 
cursor.execute(query) 
File "/home/bgrande/software/genesis/anaconda-2.0.1/lib/python2.7/site-packages/mysql/connector/cursor.py", line 494, in execute 
self._handle_result(self._connection.cmd_query(stmt)) 
File "/home/bgrande/software/genesis/anaconda-2.0.1/lib/python2.7/site-packages/mysql/connector/connection.py", line 683, in cmd_query 
statement)) 
File "/home/bgrande/software/genesis/anaconda-2.0.1/lib/python2.7/site-packages/mysql/connector/connection.py", line 612, in _handle_result 
eof = self._handle_eof(self._socket.recv()) 
File "/home/bgrande/software/genesis/anaconda-2.0.1/lib/python2.7/site-packages/mysql/connector/connection.py", line 554, in _handle_eof 
eof = self._protocol.parse_eof(packet) 
File "/home/bgrande/software/genesis/anaconda-2.0.1/lib/python2.7/site-packages/mysql/connector/protocol.py", line 252, in parse_eof 
raise errors.InterfaceError(err_msg) 
mysql.connector.errors.InterfaceError: Failed parsing EOF packet. 

After this, it seems like the connection with the MySQL server is lost. Another attempt at running get_database() returns the following error:

>>> cnx.get_database() 
Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
File "/home/bgrande/software/genesis/anaconda-2.0.1/lib/python2.7/site-packages/mysql/connector/connection.py", line 1200, in get_database 
return self._info_query("SELECT DATABASE()")[0] 
File "/home/bgrande/software/genesis/anaconda-2.0.1/lib/python2.7/site-packages/mysql/connector/connection.py", line 1433, in _info_query 
cursor = self.cursor(buffered=True) 
File "/home/bgrande/software/genesis/anaconda-2.0.1/lib/python2.7/site-packages/mysql/connector/connection.py", line 1328, in cursor 
raise errors.OperationalError("MySQL Connection not available.") 
mysql.connector.errors.OperationalError: MySQL Connection not available. 

This is confirmed by the is_connected() method.

>>> cnx.is_connected() 
False

Additionally, I should mention that on another computer on this LAN with a similar setup (CentOS 5.5; Python 2.7.6), I've successfully used the MySQLdb module to interact with the database. Yet, the very same Python installation with the mysql.connector module cannot (due to the same error). I've attempted to install MySQLdb on the first computer mentioned here, but I ran into issues. I thought the MySQL Connector/Python would work much more readily.

I'm afraid that this will be hard to reproduce, since it probably depends on my specific environment. Nonetheless, I would appreciate any pointers for steps I could take to narrow down where the issue lies. Thanks!