I have a REST API documentation on page 97, that gives me the rest api snippet like this below:
I did exactly the same with python. See below:
import requests
base_url = 'https://hostname/api'
session = requests.Session()
headers = {
'Content-Type' : 'application/json',
'cache-control': 'no-cache',
'x-endeavour-sessionid': '23423423werfer23f23rf2'
}
_params = {
"resourceType": "vm",
"from": "hlo",
"filter": {
[
{
"property": "storageProfileName",
"value": "testname",
"op": "="
}
]
}
}
_data = f'''{{
"name": "*",
"hypervisorType": "vmware"
}}'''
url_unprotectedvm = base_url + '/hypervisor/search'
unprotectedvm_data = session.post(url_unprotectedvm, params=_params, data=_data, headers=headers, verify=False)
print(unprotectedvm_data)
But I am getting a TypeError: unhashable type: 'list'
in line "op": "="
. I did checkout all the unhashable type list posts and tried changing the list to a tuple. But then the API throws 400 bad request. Is this a problem with the API or am i doing something wrong?
{} contains the dict not list. you should try removing {} in filters
_params = {
"resourceType": "vm",
"from": "hlo",
"filter":
[
{
"property": "storageProfileName",
"value": "testname",
"op": "="
}
]
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.