1.封装get,post,delete,post请求 api文件
# coding=utf-8
import json
import requests
class TestApi(object):
"""
/*
@param: @session ,@cookies
the request can be divided into session request and cookie request according to user's own choice
however,url and header is must ,other parameters are given by user to make it is None or not
*/
"""
def get(self,url,param,header,cookie=None,session=None,**kwargs):
if session:
return session.request("GET",url,param,headers=header,**kwargs)
elif cookie:
return requests.get(url,params=param,headers=header,cookies=cookie,**kwargs)
"""
/*
@param: @session ,@cookies
传入的是dict类型 python object 对象
header is form data: application/x-www-urlencoded
transfer data to data directly ,finally requests's submit will be like 'aa=dd&bb=ff' formation
header is json :application/json
due to the data can be 'str','dict'and tuple and so on ,so when we choose data and
data is given by dict,we must transfer it to json str,but when is json type str ,we must must
transfer python object dict to json str with json.dumps(),
finally the request submit data format is str like:
'aa=dd&bb=ff',but when choose json the submit will become like {'a': 'cc' ,'b': 'dd'} ,