HI All
i belive morpheus cypher package needs to have a better error handling,.
we are running the below error almost every day when 5 to 8 jobs run at the same time, which use the morpheus cypher package. the reason might be most of our jobs, i guess 5 to 8 of them are scheduled at the same time, out of 8 jobs one the job is erroring out with below error.
Traceback (most recent call last):
File "<stdin>", line 44, in <module>
File "<stdin>", line 25, in main
File "/var/opt/morpheus/morpheus-local/workspace/py-f85459cd-28c3-4ae8-9dc0-19b435a3b701/lib/python3.11/site-packages/morpheuscypher/__init__.py", line 85, in __init__
self.set_cypher_endpoint()
File "/var/opt/morpheus/morpheus-local/workspace/py-f85459cd-28c3-4ae8-9dc0-19b435a3b701/lib/python3.11/site-packages/morpheuscypher/__init__.py", line 103, in set_cypher_endpoint
if LooseVersion(data['buildVersion']) < LooseVersion('5.3.3'):
~~~~^^^^^^^^^^^^^^^^
KeyError: 'buildVersion'
i downloaded the source code for morpheus cypher package
at line number 103 in def set_cypher_endpoint(self) function,
current code,
def set_cypher_endpoint(self):
appliance_url = self.url
url = appliance_url + "/api/ping"
headers = {'content-type': 'application/json', 'Authorization': "BEARER %s" % self.token}
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=Warning)
r = requests.get(url=url, headers=headers, verify=self.ssl_verify)
data = r.json()
***if LooseVersion(data['buildVersion']) < LooseVersion('5.3.3'):***
self.cypher_endpoint = "/api/cypher/v1/"
else:
self.cypher_endpoint = "/api/cypher/"
i think the code should be
def set_cypher_endpoint(self):
appliance_url = self.url
url = appliance_url + "/api/ping"
headers = {'content-type': 'application/json', 'Authorization': "BEARER %s" % self.token}
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=Warning)
r = requests.get(url=url, headers=headers, verify=self.ssl_verify)
try:
data = r.json()
# Check if 'buildVersion' is present
if 'buildVersion' in data and LooseVersion(data['buildVersion']) >= LooseVersion('5.3.3'):
self.cypher_endpoint = "/api/cypher/"
else:
# Use the fallback endpoint if buildVersion is missing or < 5.3.3
self.cypher_endpoint = "/api/cypher/v1/"
except (ValueError, KeyError):
# Fallback to /api/cypher/v1/ if there's a JSON error or missing 'buildVersion'
self.cypher_endpoint = "/api/cypher/v1/"
who ever was developing that package, can you please take a look?