python请求发布请求

时间:2017-02-02 09:23:07

标签: python json python-requests

请求有效负载: (假设空间在那里)

{input01: {Input: "adress", adress: "g", FirstName: "", LastName: ""}, Locale: "en"}
     Locale:"en"
input01:{Input: "adress", adress: "g", FirstName: "", LastName: ""}
  FirstName:""
  adress:"g"
  Input:"adress"
  LastName:"

这是我的尝试(返回400)。

data = {
      "input01": {
        "Input": "adress",
        "adress": "test",
        "FirstName": "",
        "LastName": ""
      },
      "Locale": "en"
    }

r = requests.post(url, data=data)
print(str(r.text))

1 个答案:

答案 0 :(得分:2)

您没有发布JSON。当您将字典传递给application/x-www-form-urlencoded参数时,它将被编码为json请求,而不是HTML表单的默认编码。

要发布JSON,请使用r = requests.post(url, json=data) 参数:

{{1}}