Centos7使用python3连接inception报错解决办法

inception支持mysqldb库但不支持pymysql库,无奈mysqldb库不兼容py3,直接使用pymysql 连接inception报错如下:

ValueError: invalid literal for int() with base 10: 'Inception2'

需要修改pymysql源码修改connections.py及 cursors.py文件

# find / -name "connections.py"
# find / -name "cursors.py"

connections.py文件修改:
781行:

 781     def _request_authentication(self):
 782         # https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse
 783         #if int(self.server_version.split('.', 1)[0]) >= 5:
 784         #    self.client_flag |= CLIENT.MULTI_RESULTS
 785         try:
 786             if int(self.server_version.split('.', 1)[0]) >= 5:
 787                 self.client_flag |= CLIENT.MULTI_RESULTS
 788         except:
 789             if self.server_version.split('.', 1)[0] == 'Inception2':
 790                 self.client_flag |= CLIENT.MULTI_RESULTS

cursors.py文件修改:
355行:

355     def _show_warnings(self):
356         if self._warnings_handled:
357             return
358         self._warnings_handled = True
359         #if self._result and (self._result.has_next or not self._result.warning_count):
360         if self._result:
361             return

修改完后可用。

原文地址:https://www.cnblogs.com/aresxin/p/1w3rwf.html