The first chapter of python+requests interface automation introduction (including get method post method and return value processing.)

This chapter mainly talks about the introduction of interface automation, including the get method post method and the processing of the return value.

 The most commonly seen in interface testing are the get method and the post method.

get method:

For the get method provided by requests, there are several commonly used parameters:

url: the address url of the interface

headers: custom request headers (headers), for example: content-type = application/x-www-form-urlencoded

params: used to pass the parameters used by the test interface, here we use the dictionary form (key: value) in python to pass the parameters.

timeout: Set the maximum time for interface connection (over this time, a timeout error will be thrown)

url=‘http://api.shein.com/v2/member/logout’
header={‘content-type’: application/x-www-form-urlencoded}
param={‘user_id’: 123456,‘email’: [email protected]}
timeout=0.5
requests.get(url, headers=header, params=param, timeout=timeout)
url=‘http://api.shein.com/v2/member/logout’
header={‘content-type’: application/x-www-form-urlencoded}
param={‘user_id’: 123456,‘email’: 123456@163.com}
timeout=0.5
requests.get(url, headers=header, params=param, timeout=timeout)

POST method

        Similar to the get method, you only need to set the corresponding parameters. Let's take a chestnut directly and go directly to the code:

url=‘http://api.shein.com/v2/member/login’
header={‘content-type’: application/x-www-form-urlencoded}
data={‘email’: [email protected],‘password’: 123456}
timeout=0.5
requests.post(url, headers=header, data=data, timeout=timeout)
url=‘http://api.shein.com/v2/member/login’
header={‘content-type’: application/x-www-form-urlencoded}
data={‘email’: 123456@163.com,‘password’: 123456}
timeout=0.5
requests.post(url, headers=header, data=data, timeout=timeout)




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325337190&siteId=291194637