如何创建正确的看跌期权请求并修复422错误

时间:2019-02-18 08:01:57

标签: python-3.x blueprint flask-restplus

我正在尝试更新数据库中的数据。一切都很好,但是当我向请求中添加@ blp.arguments(UserSchema)和数据时,我得到422错误(422无法处理的实体) 你能帮我解决吗?这是我的代码

@api.definition("User")
class UserSchema(StrictSchema):
    email = fields.String(required=True, description="The email of the user")
    description = fields.String(required=True, description="The full name of the user")





@blp.route("project/<int:project_id>", methods=["PUT"])
class Project(MethodView):
    # pylint: disable=no-self-use
    @login_required
    @blp.doc(
        parameters=[
        #{"name": "project_id", "in": "path", "description": "The ID of the user"},
        #{"name": "parent_id", "in": "body", "description": "The project description"},
        {"name": "email", "in": "body", "description": "The project code"},
        {"name": "description", "in": "body", "description": "The project description"},

        #{"name": "patients", "in": "body", "description": "The project description"},
    ]
)
    @blp.arguments(UserSchema)
    @blp.response(ProjectsSchema)
    def put(self, user: dict) -> ProjectsSchema:
        """Update a user
        ---
        :param user: The user data from request body
        :param project_id: The ID of the user being looked up
        :return:
        """
        print(user)
        try:
            query = db.session.query(ProjectModel).join(UserProject).filter(UserProject.user_id == current_user.id)
            found_project = query.filter(ProjectModel.project_id == 7).first()#project_id).first()
            found_project.description="description"
            db.session.commit()

        return found_project

这是我调用put方法的文件

def test_update_project(test_client):
    projects, _, headers = setup_projects(1)
    data = {"email": "new_email@test.com", "description": "New Fullname"}
    res = test_client.put(f"v2/project/{projects[0].project_id}", data=json.dumps(data), headers=headers)
    assert res.status_code == 200

正如我之前所说,一切正确,直到我添加@ blp.arguments(UserSchema)和data = json.dumps(data)。 在我的跟踪中,我看到错误Nonetype对象没有属性定义

0 个答案:

没有答案