[TIL] Error 1: JSONDecodeError

Jene Hojin Choi·2021년 2월 21일
0

Error List

목록 보기
1/5
post-thumbnail

Error 1. JSONDecodeError

raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)


If the data being deserialized is not a valid JSON document, a JSONDecodeError will be raised.

이는 json.loads를 쓸때 걸리는데, 받는 값이 없거나 deserialize되고 있는 값이 json 형식이 아닐때 에러가 난다.
이런 경우에는 다음과 같이 except 를 써주어 에러 메세지를 보내주어야한다.

try:
    코드 
except JSONDecodeError:
    return JsonResponse({'message': 'JSON_DECODE_ERROR'}, status=400)

0개의 댓글