调用:res = rest.delete(api, json=para_data, headers=header)
# delete方法
def delete(self, url, **kwargs):
return self.request(url, "DELETE", **kwargs)
# request方法:
def request(self, url, method, data=None, json=None, **kwargs):
url = self.api_url + url
headers = dict(**kwargs).get("headers")
params = dict(**kwargs).get("params")
files = dict(**kwargs).get("files")
cookies = dict(**kwargs).get("cookies")
self.request_log(url, method, data, json, params, headers, files, cookies)
if method == "GET":
return self.session.get(url, **kwargs)
if method == "POST":
return requests.post(url, data, json, **kwargs)
if method == "PUT":
if json:
data = complexjson.dumps(json)
return self.session.put(url, data, **kwargs)
if method == "DELETE":
return requests.delete(url, **kwargs)
if method == "PATCH":
if json:
data = complexjson.dumps(json)
return self.session.patch(url, data, **kwargs)
打断点调试后发现kwargs中的原有的字典json赋给了参数json,然后kwargs就只有headers了,导致请求requests.delete(url, kwargs)时kwargs缺少了json入参,怎么样json参数能一直在**kwargs中呢?
你如果要把 json放在kwargs中,那么 request 方法的参数中就不要写 json=None