This has always worked until the update from 2.1.0p31 to 2.2.0p7 (enterprise edition). Now it returns a python dictionary instead of json. The parameter output_format seems to have no effect.
Selecting the desired format xml, json or python works when I test with parameters in URL like: https://server/site/check_mk/host_inv_api.py?host=myhost&output_format=xml
Is something wrong with my POST request? Was there a change or is this a bug?
The methods have not changed. 2.3 still has the different output formats and parameters.
How do you read your “r”? r.json() will read the JSON and transform it to a python dictionary. r.text will give you the JSON-string if you want it raw.
The script always used r.json() to convert json to python dictionary. After upgrading to cmk 2.2.0p7 an error like “no valid json data, expecting double quotes” occurred. And indeed, since the update it returns single quotes around keys and values.
Parameter “output_format” has no effect when doing this post request. I didn’t change the post request and I can’t find a mistake in it. Other parameters like hosts list, username and password are working. I recently added the path parameter to only query the networking node and it works.
As the api already returns a python dictionary I could avoid the conversion from json and work with the returned python dictionary directly. I found this code to do so: ast.literal_eval(r.text)
But I try to avoid evaluation of code because it may be a security risk. That’s why I’m looking for a way to get “output_format” in this post request working again.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.