简体   繁体   English

获取 500 内部服务器错误 Flask 应用程序

[英]getting 500 Internal server error Flask app

While trying to reach http://localhost:5000/token through Postman (POST request)尝试通过 Postman(POST 请求)到达 http://localhost:5000/token

POST request details: { "email": "u999@jht.com", "password": "xdE56" } POST 请求详情:{ "email": "u999@jht.com", "password": "xdE56" }

The purpose is to test the login function.目的是测试登录function。 An access token should appear in the response body.访问令牌应出现在响应正文中。
I get the following error我收到以下错误

* Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 112-744-944
127.0.0.1 - - [07/Dec/2021 18:08:40] "POST /token HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask/app.py", line 2328, in __call__
    return self.wsgi_app(environ, start_response)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask/app.py", line 2314, in wsgi_app
    response = self.handle_exception(e)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask_restful/__init__.py", line 269, in error_router
    return original_handler(e)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask/app.py", line 1760, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
    raise value.with_traceback(tb)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask/app.py", line 2311, in wsgi_app
    response = self.full_dispatch_request()
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask/app.py", line 1834, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask_restful/__init__.py", line 269, in error_router
    return original_handler(e)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask/app.py", line 1737, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
    raise value.with_traceback(tb)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask/app.py", line 1832, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask/app.py", line 1818, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask_restful/__init__.py", line 458, in wrapper
    resp = resource(*args, **kwargs)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask/views.py", line 88, in view
    return self.dispatch_request(*args, **kwargs)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask_restful/__init__.py", line 573, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/resources/token_management.py", line 33, in post
    access_token = create_access_token(identity=user.id, fresh=True)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask_jwt_extended/utils.py", line 157, in create_access_token
    return jwt_manager._create_access_token(identity, fresh, expires_delta, user_claims)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask_jwt_extended/jwt_manager.py", line 479, in _create_access_token
    json_encoder=config.json_encoder
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask_jwt_extended/tokens.py", line 77, in encode_access_token
    json_encoder=json_encoder)
  File "/root/PycharmProjects/pythonProject/smilecook-test-L_1-4/venv/lib/python3.7/site-packages/flask_jwt_extended/tokens.py", line 31, in _encode_jwt
    json_encoder=json_encoder).decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'

The Postman response body should display the access_token. Postman 响应正文应显示 access_token。

Encoding issue by any chance?编码问题有任何机会吗?

Including the piece of code in Flask that is handling the route (ie doing your processing after the POST) usually makes it easier to debug an issue.在 Flask 中包含处理路由(即在 POST 之后进行处理)的代码通常可以更容易地调试问题。

From the error logs, I suspect there's a piece of code somewhere that is doing <string>.decode('utf-8') but in Python3, all strings are unicode so the usual solution is to drop the decode('utf-8') .从错误日志中,我怀疑某处有一段代码正在执行<string>.decode('utf-8')但在 Python3 中,所有字符串都是 unicode 所以通常的解决方案是删除decode('utf-8') If this is not your code (eg you are using a library), you need to make sure the version of the library you're using is compatible with Python3 eg see this stackoverflow response for PyJWT library if that is the library you're using.如果这不是您的代码(例如,您使用的是库),您需要确保您使用的库版本与 Python3 兼容,例如,如果您使用的是PyJWT库,请参阅stackoverflow 响应.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在读取/显示数据时使用烧瓶/python/sqlalchemy 出现内部 500 错误 - Getting an Internal 500 error with flask/python/sqlalchemy in reading/displaying data 使用Flask和Jinja时500内部服务器错误 - 500 Internal Server Error When Using Flask and Jinja 使用 Flask JWT 时出错,AttributeError: &#39;list&#39; 对象没有属性 &#39;id&#39; 并显示 500 内部服务器错误 - getting error while using Flask JWT, AttributeError: 'list' object has no attribute 'id' and shows 500 Internal server error 为什么我会收到 500 内部服务器错误消息? - Why am I getting the 500 Internal Server Error message? 为什么我的 python 应用程序继续收到 500 内部服务器错误? - Why is my python app continues to get a 500 Internal Server Error? 烧瓶错误 500 内部服务器错误。 使用电子邮件/密码进行 Firebase 身份验证 - Flask error 500 Internal Server Error. Firebase-authentication with email/password 无法解决 500(内部服务器错误)代码 - Cannot Resolve a 500 (Internal Server Error) Code 即使按照几个类似问题中的建议进行修复,也会出现 500 内部服务器错误 - Getting a 500 Internal Server Error even with fixes as recommended in a couple of similar questions 为什么通过python请求调用rest api时出现500 Internal Server Error? - Why am I getting 500 Internal Server Error when calling post rest api via python request? Flask 返回 500 成功返回后内部错误 - Flask returning 500 Internal error after successful return
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM