登录会话每隔几秒就会过期

问题描述 投票:0回答:2

我使用标准的Flask-Login库来访问我的应用程序。登录超时为300分钟。在我的本地机器上,这个库正常工作 - 我登录到应用程序,执行smth并单击“注销” - 一切正常。然后我“推”我的应用程序到heroku并登录。我可以做一些事情,但在10-15秒后会话消失,我必须重新登录。

错误是什么?

我试图解决这个问题,但没有任何帮助。我的heroku计划是“爱好/开发”。如果您有任何想法,可以帮助我吗?

#Init sessions 
Session(app) 
#Login manager 
loginmanager = LoginManager() ... ... 
# Call 'login required' function, when I need to protect my function: 
# View function for custom admin 
@app.route(def_route+'/', methods=['GET', 'POST']) 
@app.route("/", methods=['GET', 'POST']) 
@login_required 
def index(): 
   #try: 
   errorvar = 0 ...`

我使用的软件:

alembic==1.0.7
APScheduler==3.6.0
asn1crypto==0.24.0
Babel==2.6.0
blinker==1.4
certifi==2019.3.9
cffi==1.12.2
chardet==3.0.4
Click==7.0
cryptography==2.6.1
Flask==1.0.2
Flask-Admin==1.5.3
Flask-BabelEx==0.9.3
Flask-JWT==0.3.2
Flask-JWT-Extended==3.18.0
Flask-Login==0.4.1
Flask-LoginManager==1.1.6
Flask-Mail==0.9.1
Flask-Migrate==2.4.0
Flask-Principal==0.4.0
Flask-Script==2.0.6
Flask-Security==3.0.0
Flask-Session==0.3.1
Flask-SQLAlchemy==2.3.2
Flask-WTF==0.14.2
gunicorn==19.9.0
idna==2.8
itsdangerous==1.1.0
Jinja2==2.10
Mako==1.0.7
MarkupSafe==1.1.0
ndg-httpsclient==0.5.1
passlib==1.7.1
psycopg2==2.7.6.1
pusher==2.1.3
pyasn1==0.4.5
pycparser==2.19
PyJWT==1.4.2
PyNaCl==1.3.0
pyOpenSSL==19.0.0
python-dateutil==2.8.0
python-editor==1.0.4
pytz==2018.9
requests==2.21.0
six==1.12.0
speaklater==1.3
SQLAlchemy==1.2.18
tzlocal==1.5.1
urllib3==1.24.1
virtualenv==16.2.0
Werkzeug==0.14.1
WTForms==2.2.1

设置会话时间:

@app.before_request
def make_session_permanent():
    session.permanent = True
    app.permanent_session_lifetime = timedelta(minutes=300)
python-3.x heroku flask flask-login
2个回答
2
投票

你应该避免本地qazxsw poi或qazxsw poi qazxsw poi,在Heroku上配置其中一项服务:

  • redis:RedisSessionInterface
  • memcached:MemcachedSessionInterface
  • mongodb:MongoDBSessionInterface
  • sqlalchemy:SqlAlchemySessionInterface

每次请求都会删除Heroku的FS和内存。


1
投票

您应该在几个场景中尝试redis for session作为dyno clear FS,例如24小时一次和每次部署。由于非共享缓存(如果使用FS),使用多个dyno可能会导致相同的问题。

© www.soinside.com 2019 - 2024. All rights reserved.