Python Interface Test-get request (i)

Source: Internet
Author: User

Python is used as an excuse to test the requests module, the first to import the requests library, PIP install requests

1. Get Direct Request mode

Take Douban as an example:

' https://read.douban.com/ '  = requests.get (url=URL)#  Status_code for the returned status code print(respose.status _code)#  text for the returned data print(respose.text)

Request Result: The return status code is 200, indicating that the requested server is responding properly, but it does not indicate that the interface is normal

Judging the interface is normal, look at the return data, if the return data to achieve the expected results to calculate the interface is normal

  

2. Get Send parameter Test

Request Code:

Request the search function of watercress, search data is three body

The parameters sent must be in the form of a dictionary, and multiple parameters can be sent. Send format: {' key1 ': value1 ', ' key2 ': ' value2 ', ' Key3 ', ' value3 '}

The following code asks for the url+ parameter and wants to equal the requested Url=https://read.douban.com/search? Q= Three Body

# --*--coding:utf-8--*-- Import  'https://read.douban.com/search'= {'q' :' three body '= Requests.get (Url=search_url, params=Search_word)  Print(respose.status_code)print(respose.text)

Response Result:

You can see a watercress in the response data. Read search: Three body

  

3. Return information of response results

Status_code: Response Status Code

URL: Requested URL

Encoding: Encoding format

Headers: Response Header

Request: How it is requested

Cookies:cookies data

Raw: Returns the original response body

Additional return information:

Content: Usually used for compression, such as gzip, will be self-defined decompression

JSON (): Built-in JSON decoder

  

Interface Test series essay, reference Shanghai-leisurely "Python interface Automation"

Python Interface Test-get request (i)

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.