[英]gunicorn and flask-jwt-extended not getting current user
I've been building an app that uses flask, flask_jwt_extended
and the decorator @jwt_required
around protected functions that need an access token to access.我一直在构建一个应用程序,它使用flask、 flask_jwt_extended
和装饰器@jwt_required
围绕需要访问令牌才能访问的受保护函数。 From these endpoints, I can use flask_jwt_extended
's get_current_user
function to fetch the currrent user.从这些端点,我可以使用flask_jwt_extended
的get_current_user
函数来获取当前用户。
This has been working fine while in development, but now I'm planning to serve a production application using gunicorn
.这在开发过程中一直运行良好,但现在我计划使用gunicorn
为生产应用程序提供服务。 However, when I run the gunicorn
server, it seems like the get_current_user
function is always returning none.但是,当我运行gunicorn
服务器时,似乎get_current_user
函数总是不返回任何内容。 For example, the following code works with python3 -m flask run
, but not with gunicorn run:app -b localhost:5000
.例如,以下代码适用于python3 -m flask run
,但不适用于gunicorn run:app -b localhost:5000
。 What could be the problem here?这里可能有什么问题?
@jwt_required
def get_user_by_id(user_id: str) -> Dict[str, Any]:
# returns user when using flask run, but not with gunicorn
curr_user = get_current_user()
sync
class ?你使用多个工人和sync
类吗? Maybe try to look at gunicorn worker-class也许试着看看 枪炮工人阶级If you try to use the sync worker type and set the threads setting to more than 1, the gthread worker type will be used instead.如果您尝试使用同步工作线程类型并将线程设置设置为大于 1,则将使用 gthread 工作线程类型。
worker_class = 'gthread' worker_class = 'gthread'
JWT_SECRET_KEY
need to have the same value all over each workers JWT_SECRET_KEY
需要在每个工人JWT_SECRET_KEY
都具有相同的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.