-
inconsistent use of tabs and spaces in indentationweb/backend 2022. 4. 13. 10:44728x90
Flask프레임워크를 사용하여 API 구현하기 위해 app.py에 아래와 같은 코드를 작성했다.
@app.route('/tweet', methods=['POST']) def tweet(): payload = request.json user_id = int(payload['id']) tweet = payload['tweet'] if user_id not in app.users: return '사용자가 존재하지 않습니다.', 400 if len(tweet) > 300: return '300자를 초과했습니다', 400 user_id = int(payload['id']) app.tweets.append({ 'user_id' : user_id, 'tweet' : tweet })
저장하고 API 콜을 했는데 오류가 발생했다.
TabError: inconsistent use of tabs and spaces in indentation 처음에 에러 사항을 제대로 읽지 않아서 엄청 헤매었는데
TabError에 그대로 써있듯 들여쓰기를 tabs와 spaces를 혼용해서 발생한 에러였다.
육안으로는 탭과 스페이스가 똑같이 느껴지지만 파이썬 인터프리터는 다르게 받아들인다.
따라서 하나로 통일해서 사용해야 한다.
728x90