Commit e933a101cad269a50b258f8d151fdb961e22a782

Authored by lixi
1 parent 4493a993

更新文件

Showing 1 changed file with 19 additions and 7 deletions
commons/MySession.py
@@ -93,12 +93,14 @@ class mysession(requests.Session): @@ -93,12 +93,14 @@ class mysession(requests.Session):
93 # url = url.replace(" ", "") 93 # url = url.replace(" ", "")
94 if host!=None: 94 if host!=None:
95 if "http:" in url: 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 elif "https:" in url: 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 def get_session_client(self, account, **kwargs): 105 def get_session_client(self, account, **kwargs):
104 "get_session和get_session_client的方法只能用一个" 106 "get_session和get_session_client的方法只能用一个"
@@ -166,7 +168,17 @@ class mysession(requests.Session): @@ -166,7 +168,17 @@ class mysession(requests.Session):
166 # 记录日志 168 # 记录日志
167 log.info("{0:=^86}".format('')) 169 log.info("{0:=^86}".format(''))
168 log.info(url) 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 log.info("{}\n{}\n".format(url, kwargs)) 182 log.info("{}\n{}\n".format(url, kwargs))
171 # 进行请求 183 # 进行请求
172 re = super().request(method , url, **kwargs,timeout=self.timeout) 184 re = super().request(method , url, **kwargs,timeout=self.timeout)
@@ -283,7 +295,7 @@ my.set_mark() @@ -283,7 +295,7 @@ my.set_mark()
283 # 哈尔滨客户端session 295 # 哈尔滨客户端session
284 # sessionHeb = mysession().cliLogin("hd_userName_01") 296 # sessionHeb = mysession().cliLogin("hd_userName_01")
285 #获取对应市场session 297 #获取对应市场session
286 -# sy1=mysession("host1").get_session_client("sy_user01") 298 +sy1=mysession("host1").get_session_client("sy_user01")
287 # heb=mysession("host1").get_session_client("heb_user01") 299 # heb=mysession("host1").get_session_client("heb_user01")
288 hg=mysession("host2").get_session_client("hg_user01") 300 hg=mysession("host2").get_session_client("hg_user01")
289 # 检测登录接口 301 # 检测登录接口