Jump to content

[Solved] flask_session: runtime error secret_key not set even though it's already set


Recommended Posts

Hi all, need some coding help

In my python file I have set the secret_key but whenever I tried to login into my website, it still gives the error of key not being set. I have tested the code locally and it works, not sure why it gives the error when I move the code to the live website.

from flask import (
    Flask,
    request,
    jsonify,
    render_template,
    session,
    redirect,
    url_for,
    send_file,
)
import Account
import os
from flask_session import Session
import secrets

app = Flask(__name__)
app.config['SECRET_KEY'] = secrets.token_hex(16)
app.config["UPLOAD_FOLDER"] = "users/uploads"

# Session configuration
session_dir = os.path.join(os.getcwd(), "flask_session")
app.config["SESSION_FILE_DIR"] = session_dir

Session(app)

 

Screenshot2024-02-10024933.thumb.png.44824caa3b1b6b8fef04e1bec5d6b19d.png 

Edited by Shro
Link to comment
Share on other sites

Found the fix already.

# Replace 
app.config['SECRET_KEY'] = secrets.token_hex(16) 
# with 
app.secret_key = secrets.token_hex(16) # Can use b'________' as well instead of secrets.token_hex(16) to load the site faster
# Remove this
Session(app)

 

Link to comment
Share on other sites

  • Shro changed the title to [Solved] flask_session: runtime error secret_key not set even though it's already set

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...