Commit 4cdb192bf63fdb41b203e85d65c84034a8d9fb62
1 parent
f2da266e
1
Showing
1 changed file
with
18 additions
and
6 deletions
commons/MySession.py
... | ... | @@ -93,12 +93,14 @@ class mysession(requests.Session): |
93 | 93 | # url = url.replace(" ", "") |
94 | 94 | if host!=None: |
95 | 95 | if "http:" in url: |
96 | - d1 = re.match(r"http://(.+?)/", url).group(1).split(":")[0] | |
97 | - url = re.sub(r"http://(.+?)/", r"http://" + host[d1] + "/", url) | |
96 | + d1=re.match(r"http://(.+?)/", url).group(1) | |
97 | + d2 = d1.split(":")[0] | |
98 | + url = re.sub(r"http://(.+?)/", r"http://" + host[d2] + "/", url) | |
98 | 99 | elif "https:" in url: |
99 | - d1 = re.match(r"https://(.+?)/", url).group(1).split(":")[0] | |
100 | - url = re.sub(r"https://(.+?)/", r"https://" + host[d1] + "/", url) | |
101 | - return url | |
100 | + d1=re.match(r"https://(.+?)/", url).group(1) | |
101 | + d2 = d1.split(":")[0] | |
102 | + url = re.sub(r"https://(.+?)/", r"https://" + host[d2] + "/", url) | |
103 | + return url,d1 | |
102 | 104 | |
103 | 105 | def get_session_client(self, account, **kwargs): |
104 | 106 | "get_session和get_session_client的方法只能用一个" |
... | ... | @@ -166,7 +168,17 @@ class mysession(requests.Session): |
166 | 168 | # 记录日志 |
167 | 169 | log.info("{0:=^86}".format('')) |
168 | 170 | log.info(url) |
169 | - url=self.url_pro(url,self.host) | |
171 | + #处理url | |
172 | + url,host=self.url_pro(url,self.host) | |
173 | + #处理header | |
174 | + if "UAP_accessToken" in kwargs["headers"].keys(): | |
175 | + kwargs["headers"]["UAP_accessToken"] = self.re.json()["data"]["accessToken"] | |
176 | + elif "UAP_refreshToken" in kwargs["headers"].keys(): | |
177 | + kwargs["headers"]["UAP_refreshToken"] = self.re.json()["data"]["refreshToken"] | |
178 | + elif "UAP_firmId" in kwargs["headers"].keys(): | |
179 | + kwargs["headers"]["UAP_firmId"] = self.re.json()["data"]["user"]["firmId"] | |
180 | + elif "Host" in kwargs["headers"].keys(): | |
181 | + kwargs["headers"]["Host"]=host | |
170 | 182 | log.info("{}\n{}\n".format(url, kwargs)) |
171 | 183 | # 进行请求 |
172 | 184 | re = super().request(method , url, **kwargs,timeout=self.timeout) | ... | ... |