Flask session key error

1. The code where the error occurs:

self.authorize_ip = oauth.remote_app('oauth_ip', app_key='OAUTH_IP')
self.authorize_ip.authorized_response()

2. The error message is as follows:

E:\pythonPrj\CICD-TEST\venv\Scripts\python.exe E:/pythonPrj/CICD-TEST/flask_test.py
 * Serving Flask app 'app' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 338-955-284
 * Running on all addresses.
   WARNING: This is a development server. Do not use it in a production deployment.
 * Running on http://192.168.3.8:8084/ (Press CTRL+C to quit)
Access denied:error=The session is unavailable because no secret key was set.  Set the secret_key on the application to something unique and secret.

3. The root cause of the error:

  • Session background: In flask, after the user logs in, the logged-in user information is stored through the session method, which is convenient for identifying the logged-in user's information in the web page, or carrying the user's information to complete some data persistence operations.
  • Source of error: using session in flask requires configuring keys, and in flask requires manually configuring keys. django will automatically generate secret_key.

4. Solutions:

  • Add SECRET_KEY = 'zidingyisecretkey' in the configuration file, just copy mine and add it to the config file.
import os
from celery.schedules import crontab


class Config(object):
    SECRET_KEY = 'zidingyisecretkey'
    APP_NAME = 'app'
    PROJECT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
    SERVER_HOST = '192.168.3.8'
    SERVER_PORT = '8084'
    HOST_ADDRESS = 'http:{0}:{1}'.format(SERVER_HOST, SERVER_PORT)
    DEBUG = True

Guess you like

Origin blog.csdn.net/eettttttt/article/details/132095358