简体   繁体   English

python请求发布请求

[英]python requests post request

request payload: (The spaces are suppose to be there) 请求有效负载:(假定空间在那里)

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

This is my attempt (Which returns a 400). 这是我的尝试(返回400)。

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

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

You are not posting JSON. 您没有发布JSON。 When you pass a dictionary to the data argument, it will be encoded to a application/x-www-form-urlencoded request instead, the default encoding for HTML forms. 当您将字典传递给data参数时,它将被编码为application/x-www-form-urlencoded请求,这是HTML表单的默认编码。

To post JSON, use the json parameter: 要发布JSON,请使用json参数:

r = requests.post(url, json=data)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM