2

I am using waitress on IIS with Flask.

I have a route that sets a session as follows

@gp_clinicals_bp.route("/setting", methods=["POST","GET"])
def gp_clinicals():
    session["gp_clinicals_meds_repeat"] = "123456"
    return session["gp_clinicals_meds_repeat"]

This returns, unsurprisingly:

123456

I have another route as follows:

@gp_clinicals_bp.route("/testing", methods=["POST","GET"])
def gp_clinicals_test():
    return session["gp_clinicals_meds_repeat"]

Now, I get nothing back and the following in the error log

2022-08-02 20:03:51,126 - ERROR - app.py - log_exception - 1455 - Exception on /gp-clinicals/medication-repeat [GET]
Traceback (most recent call last):
  File "C:\Python310\lib\site-packages\flask\app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Python310\lib\site-packages\flask\app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Python310\lib\site-packages\flask\app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Python310\lib\site-packages\flask\app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "E:\Apps\dev\digital\gp_clinicals\gp_clinicals.py", line 158, in gp_clinicals_medication_repeat
    return str(session["gp_clinicals_meds_repeat"])
KeyError: 'gp_clinicals_meds_repeat'
2022-08-02 20:03:51,128 - ERROR - __init__.py - handle_error_500 - 92 - 500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

I'm the only one on the server. Below is a snippet from my initilisation file:

"""Initialize Flask app."""
import logging
import os
from logging.handlers import RotatingFileHandler
from flask import Flask, render_template, flash,request
from flask_session import Session
from flask_assets import Environment

from config import Config

if Config.FLASK_ENV == "development" and Config.DD_SERVICE:
    patch_all()

sess = Session()

def init_app():
    """Create Flask application."""
    app = Flask(__name__, instance_relative_config=False)
    app.config["CACHE_TYPE"] = "null"
    app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
    app.config['TEMPLATES_AUTO_RELOAD'] = True
    app.config["SESSION_TYPE"] = "filesystem"
    app.config.from_object("config.Config")
    assets = Environment()
    assets.init_app(app)
    sess.init_app(app)

What's going wrong? In the flask_session folder I am seeing files being created

enter image description here

Any advice? I tried using single apostophes instead of quotes but no go there either

The site in IIS is running through a reverse proxy in IIS - could that be doing it?

pee2pee
  • 3,619
  • 7
  • 52
  • 133

0 Answers0