我正在尝试合并基本身份验证,如此链接所示
https://github.com/miguelgrinberg/flask-httpauth/blob/master/master/examples/basic_auth.py
在我的烧瓶应用中。该应用程序部署在Heroku上。我继续遇到的错误是
@auth.verify_password
AttributeError: 'function' object has no attribute 'verify_password'
以下是我的代码
import urllib
import json
import os
import string
import random
from flask import Flask,render_template,request
from sqlalchemy import create_engine, asc
from sqlalchemy.orm import sessionmaker
from database_setup import Base, User
from flask import Flask,render_template
from flask import request
from flask import make_response
from flask import session as login_session
from flask import make_response
from flask_httpauth import HTTPBasicAuth
from werkzeug.security import generate_password_hash, check_password_hash
@auth.verify_password
def verify_password(username_or_token, password):
#Try to see if it's a token first
user_id = User.verify_auth_token(username_or_token)
if user_id:
user = session.query(User).filter_by(id = user_id).one()
else:
user = session.query(User).filter_by(username = username_or_token).first()
if not user or not user.verify_password(password):
return False
g.user = user
return True
下面是追溯
2017-02-14T19:28:58.375416+00:00 heroku[web.1]: State changed from crashed to starting
2017-02-14T19:29:01.124995+00:00 heroku[web.1]: Starting process with command `python test.py`
2017-02-14T19:29:04.255161+00:00 heroku[web.1]: Process exited with status 1
2017-02-14T19:29:04.127534+00:00 app[web.1]: Traceback (most recent call last):
2017-02-14T19:29:04.127556+00:00 app[web.1]: File "test.py", line 234, in <module>
2017-02-14T19:29:04.127594+00:00 app[web.1]: @auth.verify_password
2017-02-14T19:29:04.127622+00:00 app[web.1]: AttributeError: 'function' object has no attribute 'verify_password'
2017-02-14T19:29:04.299349+00:00 heroku[web.1]: State changed from starting to crashed
2017-02-14T19:29:04.300161+00:00 heroku[web.1]: State changed from crashed to starting
我的要求.txt文件包含以下
click==6.7
Flask==0.12
httplib2==0.9.2
itsdangerous==0.24
Jinja2==2.9.4
MarkupSafe==0.23
passlib==1.7.0
SQLAlchemy==1.1.5
virtualenv==15.1.0
Werkzeug==0.11.15
Flask-HTTPauth==3.2.2
有人可以帮我找出问题是什么吗?我有所有正确的导入,如GitHub示例所建议的,并且在我的需求中正确提到了它们。提前致谢。
在GitHub存储库上发布了同样的问题,并在此解决了。链接:https://github.com/miguelgrinberg/flask-httpauth/issues/53