본문 바로가기
Restful API

[Error] TypeError: post() got an unexpected keyword argument

by coding_su 2023. 1. 17.

📝TypeError: post() got an unexpected keyword argument 에러 해결하기

Visual Studio Code에서 유저가 친구를 추가하는 코드를 작성하는데

TypeError: post() got an unexpected keyword argument 'followeeId' 라는 에러가 발생했다

 

해당 에러는 app.py 파일에 경로를 아래 코드처럼 연결했는데

api.add_resource(FollowResource, '/follow/<int:followeeId>')

 

해당 클래스에 def post(self)로 followeeId를 입력하지 않고 코드를 입력해서 발생한 에러이다

아래코드로 수정해주었다

class FollowResource(Resource) :
    @jwt_required()
    def post(self, followeeId) : 
    
        user_id = get_jwt_identity()

        try :
            connection = get_connection()

            query = '''insert into follow(followerId, followeeId)
                    values(%s, %s);'''

            record = ( user_id, followeeId )

            cursor = connection.cursor()

            cursor.execute(query, record)

            connection.commit()

            cursor.close()
            connection.close()

        except Error as e :
            print(e)
            cursor.close()
            connection.close()

            return {"result" : "fail", "error" : str(e)}, 500

        return {"result" : "success"}, 200

댓글