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)