Forums

DB 500 error

Hi,

Just recently started using python anywhere, trying to deploy my flask app. everything seem to work just fine but I cannot seem to connect to my DB

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager

app = Flask(__name__)
app.config['SECRET_KEY'] = '123MANFORDS329'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)
bcrypt = Bcrypt(app)
login_manager = LoginManager(app)
login_manager.login_view = 'login'
login_manager.login_message_category = 'info'

from FlaskBlog import routes

this is from my innit that works with no problems on local host I just cannot seem to access the DB and get a 500 error when trying to register new accounts or login with already created accounts. it is as if it pulls information from the DB though as it has my dummy posts from the DB.

Any help anyone could give would be great

Look in your error and server logs for details of the exception that you can use to start debugging.

From what I can see I am getting the following error: ValueError: Invalid salt

I have linked this to bcrypt but I am unsure how to resolve, does this have to be encoded differently on python anywhere cause utf-8 seems to work fine on a local host.

I imagine its coming from the following bits of code without my routes.

@app.route('/register', methods=['GET', 'POST'])
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)


@app.route('/login', methods=['GET', 'POST'])
def login():
    if current_user.is_authenticated:
        return redirect(url_for('login'))
    form = LoginForm ()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            return redirect(next_page) if next_page else redirect(url_for('home'))
        else:
            flash('Login Unsuccessful. Please check email and password', 'danger')
    return render_template('login.html', title='Login', form=form)

does it have to be encoded first then decoded before hand?

If you're getting decoding and encoding errors on PythonAnywhere and not on your local machine, that suggests that you are using Python 2 on one and Python 3 on the other, so the difference between strings and byte strings becomes important. Make sure you're using the same version of Python in both places.