简体   繁体   中英

Python Flask TypeError: '>=' not supported between instances of 'NoneType' and 'float'

Please could someone help, other similar questions have been of no use thus far.

I am serving a Python3 Flask server that has been working fine for a while now.

I just started implementing a virtual environment and did all the pip installs, but my app crashed with the following Traceback when I try to run the app withing the venv, and normally:

Traceback (most recent call last):
  File "C:\Users\jason\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2095, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Users\jason\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2080, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Users\jason\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\app.py", line 2076, in wsgi_app
    ctx.push()
  File "C:\Users\jason\AppData\Local\Programs\Python\Python310\lib\site-packages\flask\ctx.py", line 434, in push
    self.session = session_interface.open_session(self.app, self.request)
  File "C:\Users\jason\AppData\Local\Programs\Python\Python310\lib\site-packages\flask_session\sessions.py", line 344, in open_session
    data = self.cache.get(self.key_prefix + sid)
  File "C:\Users\jason\AppData\Local\Programs\Python\Python310\lib\site-packages\cachelib\file.py", line 194, in get
    if pickle_time == 0 or pickle_time >= time():
TypeError: '>=' not supported between instances of 'NoneType' and 'float'

The error is thrown when I try to get the session data.

So I am uncertain whether it is the venv that broke this, or now something with my machine, because I rolledback on my git versions, and even pip uninstalled some of the recent imports.

Here is the Flask initializer and the first 2 functions:

from flask import Flask, request, session
from flask_session import Session
from functools import wraps
from datetime import timedelta
from json import dumps
from rest.api import api, users_api, setups_api, reports
import os
import shutil


# App Instance
app = Flask(__name__)
project_path = os.path.abspath('.')
app.config['APPLICATION_ROOT'] = project_path
app.config['SESSION_COOKIE_PATH'] = project_path + "/cookies/"
app.config['SESSION_TYPE'] = 'filesystem'
Session(app)


@app.before_request
def make_session_permanent():
    app.permanent_session_lifetime = timedelta(hours=(5))
    if request.path not in ["/api/login", "/api/get-session-data"]:
        if not session.get('user'):
            return "Sign in needed.", 403


@app.route("/api/login", methods=["POST", ])
def login():
    # login things
    session['user'] = "whatever"
    return dumps("")


@app.route("/api/get-session-data")
def give_session_data():
    session_data = {
        "user": session.get("user")
    }
    return dumps(session_data)

Venv requirements are:

bcrypt==3.2.0
cachelib==0.6.0
cffi==1.15.0
click==8.1.2
colorama==0.4.4
cryptography==36.0.2
cycler==0.11.0
distlib==0.3.4
et-xmlfile==1.1.0
filelock==3.7.1
Flask==2.1.1
Flask-Session==0.4.0
fonttools==4.33.3
greenlet==1.1.2
itsdangerous==2.1.2
Jinja2==3.1.1
kiwisolver==1.4.3
MarkupSafe==2.1.1
matplotlib==3.5.2
mysql-connector-python==8.0.28
mysqlclient==2.1.0
numpy==1.22.4
openpyxl==3.0.9
packaging==21.3
pandas==1.4.2
paramiko==2.10.3
Pillow==9.0.1
platformdirs==2.5.2
protobuf==3.20.0
psycopg2==2.9.3
pycparser==2.21
pycryptodome==3.14.1
PyJWT==2.4.0
PyNaCl==1.5.0
pyparsing==3.0.9
PyPDF2==1.27.3
python-dateutil==2.8.2
pytz==2022.1
six==1.16.0
SQLAlchemy==1.4.37
virtualenv==20.14.1
Werkzeug==2.1.0

Thank you in advance!

So I wasn't able to actually find out what went wrong.

Turns out the solution was to uninstall Python (version 3) on Windows and reinstall it again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM