requests二次封装提示得到了意外的关键字参数
来源:9-4 项目实战之主流程中cookie方法操作
慕侠622557
2021-04-19
import requests
from readIni import Read_Init
class Res_Run:
def res_get(self,url,data,header,cookie=None):
’’‘
封装GET方法,传参URL,data, headers
’’'
resGet = requests.get(url=url,data=data,headers=header,cookies=cookie)
return resGet
def res_post(self,url,data,header,cookie=None):
'''
封装post方法,传参URL,params, data, headers
'''
resPost = requests.post(url,data,header,cookie)
return resPost
def run_main(self,method,url,data,header=None,cookie=None):
readInit = Read_Init()
base_url = readInit.read_file_ini('host')
if 'http' not in url:
url = base_url + url
if method == 'get':
resRun = self.res_get(url=url,data=data,headers=header,cookies=cookie)
elif method == 'post':
resRun = self.res_post(url=url,data=data,headers=header,cookies=cookie)
return resRun
reques_main = Res_Run()
if name == ‘main’:
url = '/rest/V1/external/home’
data1 = {
“groups”:50,
“customer_id”:299
}
header = {
“Content-Type”:“application/x-www-form-urlencoded”,“api-version”:“V4”,“jwt-platform”:“android”
}
param = {“groups”:10}
#print(type(param))
#print(type(header))
res = reques_main.run_main(‘get’,url,data=param,headers=header).json()
#res = requests.get(url,headers=header).json()
print(res)
File "e:/work/study/oneself/API/base/request_method.py", line 47, in <module>
res = reques_main.run_main('get',url,data=param,headers=header).json()
TypeError: run_main() got an unexpected keyword argument ‘headers’
请教老师,get 封装加了header 和cookie,执行报错,TypeError: run_main() got an unexpected keyword argument ‘headers’,不知道为啥不行
1回答
-
header 你仔细看看 你是传递的headers
032021-04-23
相似问题