【问题标题】:AttributeError: 'function' object has no attribute 'verify_password'AttributeError: 'function' 对象没有属性 'verify_password'
【发布时间】:2017-07-04 10:18:41
【问题描述】:

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

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 文件中也正确提到了它们。提前致谢。

【问题讨论】:

  • 你声明auth = HTTPBasicAuth()了吗?这是在您提供的链接中完成的,但您没有在代码中显示。
  • 是的,我做到了。这只是一个sn-p。它得到了解决。谢谢

标签: heroku flask flask-httpauth


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-03-10
    • 2022-01-26
    • 2019-05-17
    • 2014-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多