确实是我正在处理的一个非常奇怪的错误。奇怪的是,当我在 pyCharm 的 localhost 上运行同一个项目时,它运行良好,但是,当我将所有文件上传到 EC2 服务器时。我收到以下错误。该项目运行良好,因此我能够托管应用程序,但是当我发送发布请求时,我收到 HTTP ERROR CODE 500 作为响应并在控制台中出现以下错误。如果有人可以帮助我纠正这个问题,我将不胜感激 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)在我的应用程序中,这是错误开始的地方。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())
1 回答

慕运维8079593
TA贡献1876条经验 获得超5个赞
正如评论中所讨论的,这是解决方案,因此对其他人有帮助:
您需要定义一个会话并将其传递给 load 函数,如下所示:
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)
添加回答
举报
0/150
提交
取消