python requests a simple interface automation

 get method

url: Obviously, it is the address of the interface url

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

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

for example:

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.geturl, headers=header, params=param, timeout=timeout

 post method

And get a similar method, as long as the corresponding set of parameters on it. For chestnuts directly below, directly on the bar 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.posturl, headers=header, data=data, timeout=timeout

The return value interface Let's explore (the) discussion (solution) under.

Still only say that commonly used operating return value.

text: Get text interfaces return value

json (): Get Interface JSON return value () format

status_code: Returns the status code (success: 200)

headers: Returns the full request headers (headers [ 'name']: Returns the specified content headers)

encoding: Returns the character encoding format

url: Back to full url address of the interface

Guess you like

Origin www.cnblogs.com/Mr-ZY/p/11695878.html