Request encapsulation for interface automation

Target

I want to generate a response by directly reading the method, url, and data in excel. Normal requests have post and get methods, which are not necessary. At this time, the requests method can be packaged to update: get request input parameters are params, so you
need
to data should be param, otherwise ‘类似get()有两个参数,但传递了3个参数’an error will appear

class HttpRequest:
    def http_request(self,url,method,data=None,headers=None):
        s = requests.Session()
        if method.lower() == 'get':     #防止大小写写错
            res = s.get(url,params=data,headers=headers)
        else:
            res = s.post(url,data,headers=headers)
        return res
req = HttpRequest().http_request(ds[0]['url'],ds[0]['method'],eval(ds[0]['data'])) # 读取的表格里的值,你们可以直接用真实的url和data测试
print(req.json())

insert image description here

Guess you like

Origin blog.csdn.net/z12347891/article/details/129625928