Получение ошибки json.decoder.JSONDecodeError
Вот полная трассировка ошибки, которую я получаю:
ERROR 2022-11-08 13:29:54,926: Internal Server Error: /voice_chat/rooms
Traceback (most recent call last):
File "C:\Users\15512\anaconda3\lib\site-packages\asgiref\sync.py", line 451, in thread_handler
raise exc_info[1]
File "C:\Users\15512\anaconda3\lib\site-packages\django\core\handlers\exception.py", line 38, in inner
response = await get_response(request)
File "C:\Users\15512\anaconda3\lib\site-packages\django\core\handlers\base.py", line 233, in _get_response_async
response = await wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\15512\anaconda3\lib\site-packages\asgiref\sync.py", line 414, in __call__
ret = await asyncio.wait_for(future, timeout=None)
File "C:\Users\15512\anaconda3\lib\asyncio\tasks.py", line 455, in wait_for
return await fut
File "C:\Users\15512\anaconda3\lib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Users\15512\anaconda3\lib\site-packages\asgiref\sync.py", line 455, in thread_handler
return func(*args, **kwargs)
File "C:\Users\15512\anaconda3\lib\site-packages\django\views\generic\base.py", line 69, in view
return self.dispatch(request, *args, **kwargs)
request_body = json.loads(decode_request)
File "C:\Users\15512\anaconda3\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\15512\anaconda3\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\15512\anaconda3\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
ERROR 2022-11-08 13:29:54,959: HTTP POST /voice_chat/rooms 500 [0.32, 127.0.0.1:54258]
Вот мой код:
def post(self, request, *args, **kwargs):
decode_request = request.body.decode("utf-8")
print('decoded request body', decode_request)
request_body = json.loads(decode_request)
# print('request body', request_body)
room_name = request_body.get("roomName")
participant_label = request_body["participantLabel"]
# print('username', curr_username)
response = VoiceResponse()
dial = Dial()
dial.conference(
name=room_name,
participant_label=participant_label,
start_conference_on_enter=True,
)
response.append(dial)
return HttpResponse(response.to_xml(), content_type="text/xml")
Вот пример того, что я размещаю:
{"roomName":"testingUseremmanuelS21","participantLabel":"emmanuelS21","matchedUser":"testingUser"}
Вот что у меня есть в decode_request
AccountSid=***&ApiVersion=2010-04-01&ApplicationSid=***&CallSid=CAf4e
***&CallStatus=ringing&Called=&Caller=client%3AemmanuelS21&Direction=inbound&From=client%3AemmanuelS21&To=&participantLabel=emmanuelS21&roomName=testingUseremmanuelS21