I am trying to incorporate basic authentication as shown in this link
https://github.com/miguelgrinberg/Flask-HTTPAuth/blob/master/examples/basic_auth.py
in my flask app. The app is deployed on Heroku. The error I keep getting is
@auth.verify_password
AttributeError: 'function' object has no attribute 'verify_password'
Below is my code
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
Below is the traceback
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
My requirements.txt file contains the following
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
Can someone help me figure out what the issue is? I have all the correct imports as suggested on the GitHub example and also have them correctly mentioned in my requirements.txt file. Thanks in advance.
The same question was posted on the GitHub repository, and was resolved there. Link: https://github.com/miguelgrinberg/Flask-HTTPAuth/issues/53