Python interface Automation 13-data and JSON parameters silly confusing

Source: Internet
Author: User

Objective

In the post request, sometimes the body part to pass the data parameter, and sometimes the body part of the JSON parameter, then the question is: When to pass the JSON, when should pass data?

I. Identification of JSON parameters

1. In the previous 1.8 chapters, the body of the POST request usually has four types, the most common is the JSON format, this is still a lot of recognition

2. Using the Grab Bag tool to view, first open raw to see the body section, such as this, the parameter is the most outside the curly brace {} Wrapped up, this has been diagnosed as JSON format.

3. Once again, you can click on the JSON to view, click to see a few sets of parameters here are JSON parsed

4. At this time, you can use the preceding 2.2 to transmit the JSON parameters

Ii. Identification of data parameters

The 1.data parameter is this format: key1=value1&key2=value2 ... This format is obviously not curly braces

Open raw view, with the above JSON difference is still very big

2. Because this is a non-JSON, so the point of opening the JSON menu is not parsed data, this data in the WebForms inside the view

3. You can see that this parameter is displayed in the body section, the name on the left is the key value, and the value on the right is the corresponding value value, like this parameter conversion from the Python dictionary format is OK

4. This type of post when the data parameter can be transmitted, the format is as follows:

s = requests.session ()

r = S.post (URL, headers=headers, Data=d) # Here's D is the parameter of the dictionary format in the previous step

Python interface Automation 13-data and JSON parameters silly confusing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.