ValueError:没有JSON对象可以解码 - Django request.body [英] ValueError: No JSON object could be decoded - Django request.body

查看:302
本文介绍了ValueError:没有JSON对象可以解码 - Django request.body的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

request.body 包含以下内容:

"event=project.status.update&project_id=807276&project_status_code=in_progress"

但是当我这样做: p>

but when I do:

json.loads(request.body)

我得到:

ValueError: No JSON object could be decoded

我做错了什么?

推荐答案

request.body 包含表单编码数据,而不是json编码的数据。这将自动解码为 request.POST 中的Python dict。所以,不要直接用 json.loads 使用 request.body ,而应该使用 request.POST

request.body contains form-encoded data, not json-encoded data. This is automatically decoded to a Python dict in request.POST. So, instead of using request.body directly with json.loads, you should be using request.POST.

这篇关于ValueError:没有JSON对象可以解码 - Django request.body的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆