AttributeError:'function'对象没有属性'verify_password'

时间:2017-02-15 16:21:08

标签: heroku flask flask-httpauth

我正在尝试合并基本身份验证,如此链接所示

https://github.com/miguelgrinberg/Flask-HTTPAuth/blob/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

我的requirements.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示例中建议的所有正确导入,并且还在我的requirements.txt文件中正确提到了它们。提前致谢。

1 个答案:

答案 0 :(得分:0)

同样的问题发布在GitHub存储库中,并在那里得到了解决。链接:https://github.com/miguelgrinberg/Flask-HTTPAuth/issues/53