Today by this card for a long time, finally solve the discovery is a small problem, haha
Recording:
Send the POST request with request, originally when the body is normal string and the number of all smooth, today encountered the body inside there is a JSON array, the result is to report parameter error
The workaround is simply to precede the JSON array with json.dumps ([{"A": 1, "B": 2},{json2}]), just like this, be sure to note that the function is to be written outside of the brackets, and today it is because the function is written out of a single JSON
Program:
# Coding:utf-8
Import requests
Import JSON
url = "Https://XXXXX"
headers = {' UserName ': ' XXXXX ',
' Accesstoken ': ' XXXXX '}
data={
' UserName ': ' XXXXX ',
' DeviceId ': ' xxxxxxxxx ',
' appversion ': ' XXXXX '
' Datas ': json.dumps
(
[
{"DeviceId": "XXXXXXX",
"DeviceType": "XXXXX",
"Time": "2017-08-28 10:32:28",
"TimeZone": 2
"Phonetime": "2017-08-28 10:32:28"},
{Json2},
{Json3}
]
)
}
r = Requests.post (URL, headers=headers, data=data)
Print R.json ()
Python request post with JSON array in body