Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pymysql stopped working : NameError: name 'byte2int' is not defined

I am using pymysql in Python to connect to database. It was working fine but now I am getting following error :

Traceback (most recent call last) :

  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

I am using following lines to connect to my database (connection string) :

conn = pymysql.Connect(host='hostname', port=3306, user='username', passwd='password', db='mysql')
like image 951
nsjethani Avatar asked Jul 27 '18 21:07

nsjethani


2 Answers

Since the pymysql maintainer refuses to release the fix, the solution is simply to install an older version of the package:

pip3 install --user 'pymysql<0.9'
like image 63
static_rtti Avatar answered Nov 09 '22 18:11

static_rtti


I got the same error and looked like _auth.py was unable to find the reference of byte2int. I added the below line to modify _auth.py to make it work.

from util import byte2int,int2byte

Please be aware the util.py is that of pymysql as there will be util.py files in other packages as well.

like image 1
SMI Avatar answered Nov 09 '22 20:11

SMI