Flask-Bcrypt - AttributeError: 'module' ob

2019-07-10 07:54发布

I have a Flask application which has been deployed to Ubuntu instances as well as working correctly in my local virtualenv. The issue lies with Flask-Bcrypt, which extends Bcrypt. When I deploy to AWS Beanstalk I receive the follow error:

File "/opt/python/current/app/application.py", line 391, in user_login
if bc.check_password_hash(user.password, password):
File "/opt/python/run/venv/lib/python2.7/site-packages/flask_bcrypt.py", line 193, in check_password_hash
return safe_str_cmp(bcrypt.hashpw(password, pw_hash), pw_hash)
File "/opt/python/run/venv/lib64/python2.7/site-packages/bcrypt/__init__.py", line 82, in hashpw
hashed = _bcrypt.ffi.new("char[]", 128)
AttributeError: 'module' object has no attribute 'ffi'

Looking at the Bcrypt source code I can see that FFI is imported from cffi:

from cffi import FFI

As you can see from my pip output below, cffi==1.9.1 is installed. However, if I run which cffi I can see:

no cffi in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin)

System info: 64bit Amazon Linux 2016.09 v2.3.0 running Python 2.7

These packages are installed on eb deploy:

packages:
   yum:
      gcc-c++: []
      python27-devel: []
      gcc: []
      libffi-devel : []
      openssl-devel: []

I have seen this issue here which suggests a package conflict. However, I do not have py-bcrypt installed.

pip freeze returns this following:

aws-cfn-bootstrap==1.4
aws-elasticbeanstalk-tools==1.19
awscli==1.11.17
awscli-cwlogs==1.3.3
Babel==0.9.4
backports.ssl-match-hostname==3.4.0.2
bcrypt==3.1.2
boto==2.42.0
botocore==1.4.74
cffi==1.9.1
chardet==2.0.1
click==6.7
cloud-init==0.7.6
colorama==0.2.5
configobj==4.7.2
cryptography==1.7.1
docopt==0.4.0
docutils==0.11
ecdsa==0.11
enum34==1.1.6
Flask==0.12
Flask-Bcrypt==0.7.1
futures==3.0.3
idna==2.2
iniparse==0.3.1
ipaddress==1.0.18
itsdangerous==0.24
Jinja2==2.7.2
jmespath==0.9.0
jsonpatch==1.2
jsonpointer==1.0
kitchen==1.1.1
lockfile==0.8
mandrill==1.0.57
MarkupSafe==0.11
meld3==1.0.2
paramiko==1.15.1
PIL==1.1.6
ply==3.4
pyasn1==0.1.9
pycparser==2.17
pycurl==7.19.0
pygpgme==0.3
pyliblzma==0.5.3
pystache==0.5.3
python-daemon==1.5.2
python-dateutil==2.1
pyxattr==0.5.0
PyYAML==3.10
requests==1.2.3
rsa==3.4.1
simplejson==3.6.5
six==1.8.0
supervisor==3.1.3
urlgrabber==3.9.1
urllib3==1.8.2
virtualenv==12.0.7
Werkzeug==0.11.15
yum-metadata-parser==1.1.4

Any help greatly appreciated.

1条回答
女痞
2楼-- · 2019-07-10 08:16

It seems as though there is a conflict between bcrypt, py-bcrypt, and Flask-Bcrypt.

I had this same issue, so I pip uninstalled all of them. Then re-installed only bcrypt since I didn't need Flask-Bcrypt.

This resolved the error.

查看更多
登录 后发表回答