为什么这条数据POST之后,某些值消失了!

playdata = {

"FirstOpen": "ture",

"Client": {

"Name": "Chrome 35.0.1916.153",

"Company": "Google",

"Family": "Chrome"

},

"OS": {

"Name": "OS X 10.7 Lion",

"Company": "Apple Computer, Inc.",

"Family": "OS X 10"

},

"Platform": "WebMail",

"UserAgent": "Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/35.0.1916.153 Safari\/537.36",

"ReadSeconds": 5,

"Geo": {

"CountryISOCode": "RS",

"Country": "Serbia",

"RegionISOCode": "VO",

"Region": "Autonomna Pokrajina Vojvodina",

"City": "Novi Sad",

"Zip": "21000",

"Coords": "45.2517,19.8369",

"IP": "188.2.95.4"

},

"MessageID": "883953f4-6105-42a2-a16a-77a8eac79483",

"ReceivedAt": "2014-06-01T12:00:00",

"Tag": "welcome-email",

"Recipient": "john@example.com"

}

我用request post上面这条数据到我django后台
然后我在django后台用restfull api写了个api接收这条post过来的数据,但"Client"里面只有Name,Company,Family 这些键,没有值,如下图。包括OS,GEO也是这样。。。
是不是数据类型搞错了,还是我api接收过来的数据要做进一步处理,下面是我django端,直接print(request.data)的结果
谢谢。

图片描述

回答:

client 的值是字典,在传输之前你应该

>>> from urllib import urlencode

>>> data = {

... 'a': 'test',

... 'name': '魔兽'

... }

>>> print urlencode(data)

a=test&name=%C4%A7%CA%DE

试试呢

回答:

如果你没有做过任何格式化或者serialization操作的话,传输字典是可能是会有问题的,你可以试下,把需要post的字典先转为json格式的字符串,然后在后端通过json.loads(request.post)转换回来。

以上是 为什么这条数据POST之后,某些值消失了! 的全部内容, 来源链接: utcz.com/a/161235.html

回到顶部