gpt4 book ai didi

JSONDecodeError,在 Django 中使用 json.loads 时

转载 作者:行者123 更新时间:2023-12-05 07:38:49 27 4
gpt4 key购买 nike

在 Django 中使用 json.loads 时出现 JSONDecodeError。

POST 数据

(b'csrfmiddlewaretoken=ikpUI4vMMbYivTby6FUkXRGNXisF6Cgq5eRnYvqoxRoyfAkwiP5GlsBj' b'jVlh3Va4&pergunta%5B1%5D%5Bitem%5D%5B1%5D=&pergunta%5B1%5D%5Bitem%5D%5B2%5D=' b'&pergunta%5B2%5D%5Bitem%5D%5B3%5D=&pergunta%5B2%5D%5Bitem%5D%5B4%5D=&pergunt' b'a%5B2%5D%5Bitem%5D%5B5%5D=&pergunta%5B2%5D%5Bitem%5D%5B6%5D=')

def post(self, request):

data = json.loads(request.body)
pprint(data)
return HttpResponse(data)

输出错误

JSONDecodeError at /

Request Method: POST Request URL: http://localhost:8000/rma/ Django Version: 1.11.7 Exception Type: JSONDecodeError Exception Value:
Expecting value: line 1 column 1 (char 0) Exception Location: /usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py in raw_decode, line 357 Python Executable: /Users/marcelowanderley/Python-Compare/bin/python Python Version: 3.6.2

最佳答案

正如@marcelo.delta 所说,对我来说也有用......

请求.POST.dict()

关于JSONDecodeError,在 Django 中使用 json.loads 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47554800/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com