redis 培养瓶应用错误:属性错误:“NoneType”对象没有属性“sign”

4smxwvx5  于 2023-08-02  发布在  Redis
关注(0)|答案(1)|浏览(119)

我已经在AKS集群上部署了我的Flask应用程序,并使用Redis配置了flask会话后端。但是应用程序无法访问,它显示Internal Server Error。当我查看分离舱日志想了解更多信息时,我发现,

INFO:waitress:Serving on http://0.0.0.0:5000
ERROR:app:Exception on /login [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2529, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1826, in full_dispatch_request
    return self.finalize_request(rv)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
    response = self.process_response(response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
    self.session_interface.save_session(self, ctx.session, response)
  File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 171, in save_session
    session_id = self._get_signer(app).sign(want_bytes(session.sid))
AttributeError: 'NoneType' object has no attribute 'sign'
ERROR:app:Request finalizing failed with an error while handling an error
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2529, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1826, in full_dispatch_request
    return self.finalize_request(rv)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
    response = self.process_response(response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
    self.session_interface.save_session(self, ctx.session, response)
  File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 171, in save_session
    session_id = self._get_signer(app).sign(want_bytes(session.sid))
AttributeError: 'NoneType' object has no attribute 'sign'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
    response = self.process_response(response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
    self.session_interface.save_session(self, ctx.session, response)
  File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 171, in save_session
    session_id = self._get_signer(app).sign(want_bytes(session.sid))
AttributeError: 'NoneType' object has no attribute 'sign'
ERROR:app:Exception on /login [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2529, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1826, in full_dispatch_request
    return self.finalize_request(rv)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
    response = self.process_response(response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
    self.session_interface.save_session(self, ctx.session, response)
  File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 171, in save_session
    session_id = self._get_signer(app).sign(want_bytes(session.sid))
AttributeError: 'NoneType' object has no attribute 'sign'
ERROR:app:Request finalizing failed with an error while handling an error
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2529, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1826, in full_dispatch_request
    return self.finalize_request(rv)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
    response = self.process_response(response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
    self.session_interface.save_session(self, ctx.session, response)
  File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 171, in save_session
    session_id = self._get_signer(app).sign(want_bytes(session.sid))
AttributeError: 'NoneType' object has no attribute 'sign'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
    response = self.process_response(response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
    self.session_interface.save_session(self, ctx.session, response)
  File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 171, in save_session
    session_id = self._get_signer(app).sign(want_bytes(session.sid))
AttributeError: 'NoneType' object has no attribute 'sign'
ERROR:app:Exception on /login [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2529, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1826, in full_dispatch_request
    return self.finalize_request(rv)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
    response = self.process_response(response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
    self.session_interface.save_session(self, ctx.session, response)
  File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 171, in save_session
    session_id = self._get_signer(app).sign(want_bytes(session.sid))
AttributeError: 'NoneType' object has no attribute 'sign'
ERROR:app:Request finalizing failed with an error while handling an error
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2529, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1826, in full_dispatch_request
    return self.finalize_request(rv)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
    response = self.process_response(response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
    self.session_interface.save_session(self, ctx.session, response)
  File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 171, in save_session
    session_id = self._get_signer(app).sign(want_bytes(session.sid))
AttributeError: 'NoneType' object has no attribute 'sign'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1847, in finalize_request
    response = self.process_response(response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2344, in process_response
    self.session_interface.save_session(self, ctx.session, response)
  File "/usr/local/lib/python3.9/site-packages/flask_session/sessions.py", line 171, in save_session
    session_id = self._get_signer(app).sign(want_bytes(session.sid))
AttributeError: 'NoneType' object has no attribute 'sign'

字符串
app_config.py

SESSION_TYPE = "redis"
SESSION_PERMANENT = False
SESSION_USE_SIGNER = True
SESSION_REDIS = redis.Redis(host='redis-master', port=6379, password='XXXXX')


如何解决此问题?
因为它在本地环境中运行良好,配置为

SESSION_TYPE = "redis"
SESSION_PERMANENT = False
SESSION_USE_SIGNER = True
SESSION_REDIS = redis.from_url('redis://localhost:6379')


运行'redis-server'命令将启动redis服务器,我的应用程序能够从'http://localhost:5000/login'访问它,没有任何问题。

tkclm6bt

tkclm6bt1#

这可能是由于SESSION_USE_SIGNER配置设置为True所致。当设置了这个参数后,Flask-Session会在保存到Redis之前尝试对会话ID进行签名。_get_signer()方法尝试从应用程序获取签名者,但应用程序为NoneType。
这可能是因为您的Flask应用程序未配置为使用密钥。密钥用于对会话ID进行签名,因此如果未设置该密钥,_get_signer()方法将返回NoneType。

SECRET_KEY = 'your-secret-key'

字符串

相关问题