確實是我正在處理的一個非常奇怪的錯誤。奇怪的是,當我在 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
提交
取消