我不是Python的专家,我有一个小脚本,基本上会将一些数据插入mysql,由于某种原因我不时会得到这个错误而不了解解决它的问题。
Exception in thread Thread-18:
Traceback (most recent call last):
File "/usr/local/lib/python2.6/threading.py", line 522, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.6/threading.py", line 477, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/x/ListenerGet.py", line 143, in onMessageReceived
dblink.execute("""INSERT INTO `messages` (`from`,`type`,`data`,`created`) VALUES (%s,1,%s,now())""",(phonenumber,messageContent.strip()))
File "build/bdist.linux-x86_64/egg/mysql/connector/cursor.py", line 491, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "build/bdist.linux-x86_64/egg/mysql/connector/connection.py", line 635, in cmd_query
statement))
File "build/bdist.linux-x86_64/egg/mysql/connector/connection.py", line 546, in _handle_result
elif packet[4] == '\x00':
IndexError: string index out of range
Exception in thread Thread-25:
Traceback (most recent call last):
File "/usr/local/lib/python2.6/threading.py", line 522, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.6/threading.py", line 477, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/x/ListenerGet.py", line 143, in onMessageReceived
dblink.execute("""INSERT INTO `whatsapp` (`from`,`type`,`data`,`created`) VALUES (%s,1,%s,now())""",(phonenumber,messageContent.strip()))
File "build/bdist.linux-x86_64/egg/mysql/connector/cursor.py", line 491, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "build/bdist.linux-x86_64/egg/mysql/connector/connection.py", line 635, in cmd_query
statement))
File "build/bdist.linux-x86_64/egg/mysql/connector/connection.py", line 546, in _handle_result
elif packet[4] == '\x00':
IndexError: string index out of range
Exception in thread Thread-10:
Traceback (most recent call last):
File "/usr/local/lib/python2.6/threading.py", line 522, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.6/threading.py", line 477, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/x/ListenerGet.py", line 143, in onMessageReceived
dblink.execute("""INSERT INTO `messages` (`from`,`type`,`data`,`created`) VALUES (%s,1,%s,now())""",(phonenumber,messageContent.strip()))
File "build/bdist.linux-x86_64/egg/mysql/connector/cursor.py", line 491, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "build/bdist.linux-x86_64/egg/mysql/connector/connection.py", line 635, in cmd_query
statement))
File "build/bdist.linux-x86_64/egg/mysql/connector/connection.py", line 547, in _handle_result
return self._handle_ok(packet)
File "build/bdist.linux-x86_64/egg/mysql/connector/connection.py", line 489, in _handle_ok
ok_packet = self._protocol.parse_ok(packet)
File "build/bdist.linux-x86_64/egg/mysql/connector/protocol.py", line 160, in parse_ok
raise errors.InterfaceError("Failed parsing OK packet.")
InterfaceError: Failed parsing OK packet.
我的脚本主要是这样的:
import mysql.connector
SQLconn = mysql.connector.connect(
host='xxxxxx',
user='xxxx',
password="xxxx",
database='xxxxx',
use_unicode=True,
charset='utf8mb4',
autocommit=True,
time_zone='GMT'
)
dblink = SQLconn.cursor()
phonenumber = jid.split('@', 1)[0]
print("Message from %s [%s]"%(phonenumber, pushName))
dblink.execute("""INSERT INTO `messages` (`from`,`type`,`data`,`created`) VALUES (%s,1,%s,now())""",(phonenumber,messageContent.strip()))