继承 super(类名,self).方法名()
重写request方法, 调用时url不是'http'开头则默认都是接口url+传入的url,设置自己的代理
调用该类:request = MySession(testdata,api_config)
1 from requests import Session 2 3 class MySession(Session): 4 # 重写init方法,如果是不同项目,只需要改变接口url传参即可 5 def __init__(self, testdata, api_config): 6 super(MySession, self).__init__() 7 self.testdata = testdata 8 self.api_config = api_config 9 10 # 重写request 11 12 def request(self, method, url, *args, **kwargs): 13 global resp 14 if url.startswith('http') is False: 15 url = api_config['api_url'] + url 16 resp = super(MySession, self).request(method, url, *args, **kwargs) 17 return resp