[英]raise ValueError(“Deserialization requires a session”)
indeed a very weird error I am dealing with.确实是我正在处理的一个非常奇怪的错误。 Weird because the same project is working fine when I am running it on localhost in pyCharm, however, when I uploaded all the files to EC2 server.
奇怪的是,当我在 pyCharm 的 localhost 上运行同一个项目时,它运行良好,但是,当我将所有文件上传到 EC2 服务器时。 I got the following error.
我收到以下错误。
The project is running fine so I am able to host the application however when I send a post request I get HTTP ERROR CODE 500 as a response and following error in the console.该项目运行良好,因此我可以托管应用程序,但是当我发送发布请求时,我得到 HTTP ERROR CODE 500 作为响应并在控制台中出现以下错误。
If someone could help me rectify this, I would be grateful如果有人可以帮助我纠正这个问题,我将不胜感激
Traceback (most recent call last):
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask/app.py", line 2464, in __cal l__
return self.wsgi_app(environ, start_response)
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask/app.py", line 2450, in wsgi_ app
response = self.handle_exception(e)
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask_restful/__init__.py", line 2 72, in error_router
return original_handler(e)
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask/app.py", line 1867, in handl e_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask/_compat.py", line 38, in rer aise
raise value.with_traceback(tb)
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_ app
response = self.full_dispatch_request()
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask/app.py", line 1952, in full_ dispatch_request
rv = self.handle_user_exception(e)
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask_restful/__init__.py", line 2 72, in error_router
return original_handler(e)
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask/app.py", line 1821, in handl e_user_exception
reraise(exc_type, exc_value, tb)
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask/_compat.py", line 38, in rer aise
raise value.with_traceback(tb)
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask/app.py", line 1950, in full_ dispatch_request
rv = self.dispatch_request()
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask/app.py", line 1936, in dispa tch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask_restful/__init__.py", line 4 68, in wrapper
resp = resource(*args, **kwargs)
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/flask_restful/__init__.py", line 5 83, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/ubuntu/yAPI/resources/r_user.py", line 50, in post
user = user_schema.load(request.get_json())
File "/home/ubuntu/yAPI/yenv/lib/python3.6/site-packages/marshmallow_sqlalchemy/schema/load _instance_mixin.py", line 89, in load
raise ValueError("Deserialization requires a session")
ValueError: Deserialization requires a session
In my application, this is where the error was started.在我的应用程序中,这是错误开始的地方。
class UserRegister(Resource):
@classmethod
def post(cls):
# the 'load' function in marshmallow will use the data to create usermodel object
user = user_schema.load(request.get_json())
As discussed in the comments, here is the solution so it can be helpful for other people:正如评论中所讨论的,这是解决方案,因此对其他人有帮助:
You need to define a session and pass it to the load function like so:您需要定义一个 session 并将其传递给负载 function ,如下所示:
from sqlalchemy import engine #thanks to your comment
from sqlalchemy.orm import scoped_session, sessionmaker
class UserRegister(Resource):
@classmethod
def post(cls):
# the 'load' function in marshmallow will use the data to create usermodel object
sess = scoped_session(sessionmaker(bind=engine))
user = user_schema.load(request.get_json(), sess)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.