【问题标题】:pymysql stopped working : NameError: name 'byte2int' is not definedpymysql 停止工作:NameError: name 'byte2int' is not defined
【发布时间】:2019-01-05 00:46:42
【问题描述】:

我在 Python 中使用 pymysql 来连接数据库。它工作正常,但现在我开始关注error

Traceback(最近一次通话最后一次):

  File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/__init__.py", line 94, in Connect
    return Connection(*args, **kwargs)
  File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/connections.py", line 327, in __init__
    self.connect()
  File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/connections.py", line 598, in connect
    self._request_authentication()
  File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/connections.py", line 865, in _request_authentication
    data = _auth.scramble_old_password(self.password, self.salt) + b'\0'
  File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/_auth.py", line 72, in scramble_old_password
    hash_pass = _hash_password_323(password)
  File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/_auth.py", line 97, in _hash_password_323
    for c in [byte2int(x) for x in password if x not in (' ', '\t', 32, 9)]:
  File "/Users/njethani/Desktop/venv/lib/python3.6/site-packages/pymysql/_auth.py", line 97, in <listcomp>
    for c in [byte2int(x) for x in password if x not in (' ', '\t', 32, 9)]:
NameError: name 'byte2int' is not defined

我正在使用以下行连接到我的数据库(连接字符串):

conn = pymysql.Connect(host='hostname', port=3306, user='username', passwd='password', db='mysql')

【问题讨论】:

    标签: python-3.x pymysql


    【解决方案1】:

    由于pymysql维护者refuses to release the fix,解决方法就是安装老版本的包:

    pip3 install --user 'pymysql<0.9'
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的错误,看起来 _auth.py 无法找到 byte2int 的引用。我添加了以下行来修改 _auth.py 以使其工作。

      从实用程序导入 byte2int,int2byte

      请注意 util.py 是 pymysql 的,因为其他包中也会有 util.py 文件。

      【讨论】:

      • @JulianCamilleri 不幸的是,我认为这些更改尚未发布到 pypi。
      猜你喜欢
      • 2022-12-02
      • 2013-04-09
      • 1970-01-01
      • 2020-11-07
      • 2017-01-09
      • 2017-06-14
      • 2023-03-11
      相关资源
      最近更新 更多