in client/apache_shenyu_client/api.py [0:0]
def _request(self, url, json_data):
"""
base post request
"""
if not url or not isinstance(url, str) or not isinstance(json_data, dict):
print("_request url or data format error")
return False
try:
res = requests.post(url, json=json_data, headers=self.headers, timeout=5)
status_code = res.status_code
msg = res.text
except ConnectTimeout as ce:
print("connect timeout, detail is:{}".format(str(ce)))
return False
except ReadTimeout as rte:
print("read time out, detail is:{}".format(str(rte)))
return False
except RequestException as rqe:
print("request except, detail is:{}".format(str(rqe)))
return False
except Exception as e:
print("request ({}) except, detail is:{}".format(url, str(e)))
return False
else:
# According to the interface return value of the gateway registry, the request is considered successful
# only when msg==success; if the interface return value of the gateway registry changes, the judgment
# method should also be modified
if msg == "success":
return True
print("request ({}) fail, status code is:{}, msg is:{}".format(res.url, status_code, msg))
return False