mysqlconnect bug 處理一例。

babyyellow發表於2021-01-08

python  3.6  遇到這個問題。 


其實不是  python 的問題 是  mysqlconnect  驅動的問題。 


用 mysqlconnect   去連結   mysql 5.5.x 版本的資料庫的時候。  就報這個錯誤了。 



修改方法放這裡了。 


C:\Python36\Lib\site-packages\mysql\connector\protocol.py


mysql  connect   的這個  protocol.py  程式碼 

 

第 225 行 。



capabilities & ClientFlag.PLUGIN_AUTH:
    (packet
            res[].startswith()):


and res['server_version_original'].startswith("5.5.8")):


 修改為  


and (res['server_version_original'].startswith("5.5.8") or res['server_version_original'].startswith("5.5.9"))):



然後儲存 從新 連結資料庫就可以了。 


當然了 ,如果你用的 5.5.x  就再後面不停的加 or 然後加版本就行了。 


這本身是 mysql 的一個bug 


好了,問題就再這裡了。 


出錯資訊 在下面。 




  1. >>> import os ,sys

  2. >>> import dba1 as dba

  3. python 版本 ok

  4. >>> db=dba.mysql('192.168.x.x',3306,'hounew','hounew','hounew')

  5. Traceback (most recent call last):

  6.   File "C:\Python36\lib\site-packages\mysql\connector\utils.py", line 279, in read_string

  7.     idx = buf.index(end)

  8. ValueError: subsection not found


  9. During handling of the above exception, another exception occurred:


  10. Traceback (most recent call last):

  11.   File "C:\Python36\lib\site-packages\mysql\connector\connection.py", line 152, in _do_handshake

  12.     handshake = self._protocol.parse_handshake(packet)

  13.   File "C:\Python36\lib\site-packages\mysql\connector\protocol.py", line 233, in parse_handshake

  14.     packet, end=b'\x00')

  15.   File "C:\Python36\lib\site-packages\mysql\connector\utils.py", line 281, in read_string

  16.     raise ValueError("end byte not present in buffer")

  17. ValueError: end byte not present in buffer


  18. During handling of the above exception, another exception occurred:


  19. Traceback (most recent call last):

  20.   File "<pyshell#2>", line 1, in <module>

  21.     db=dba.mysql('192.168.75.100',3306,'houselib_new','houselib_new','houselib_new')

  22.   File "C:\Python36\lib\dba1.py", line 286, in __init__

  23.     self.conn = connection.MySQLConnection(host=host, port=port, user=user, password=passwd, database=database)

  24.   File "C:\Python36\lib\site-packages\mysql\connector\connection.py", line 104, in __init__

  25.     self.connect(**kwargs)

  26.   File "C:\Python36\lib\site-packages\mysql\connector\abstracts.py", line 960, in connect

  27.     self._open_connection()

  28.   File "C:\Python36\lib\site-packages\mysql\connector\connection.py", line 289, in _open_connection

  29.     self._do_handshake()

  30.   File "C:\Python36\lib\site-packages\mysql\connector\connection.py", line 155, in _do_handshake

  31.     raise errors.get_mysql_exception(msg=err.msg, errno=err.errno,

  32. AttributeError: 'ValueError' object has no attribute 'msg'

  33. >>> 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/133735/viewspace-2748529/,如需轉載,請註明出處,否則將追究法律責任。

相關文章