I need to use OVH API in my Python code but the call returns this error:
OVH API Error: This call has not been granted
import json
import ovh
client = ovh.Client(
endpoint='ovh-eu',
application_key='application_key',
application_secret='application_secret',
consumer_key='consumer_key',
)
project_id = 'project_id '
try:
result = client.get(
'/cloud/project/' + project_id + '/image',
flavorType=None,
osType=None,
region='SBG5'
)
print(json.dumps(result, indent=4))
except ovh.APIError as e:
print(f"OVH API Error: {str(e)}")
print(f"OVH Query ID: {e.response.headers.get('X-Ovh-Queryid')}")
- test in API.OVH.com console is working
return this :
(venv) PS C:\Users\user\Desktop\pythonFiles\Ovh> python step1_list_services.py
OVH API Error: This call has not been granted
OVH-Query-ID: EU.ext-3.655b414a.69585.e84e84691cd2e05baa9eec9585016b18
OVH Query ID: EU.ext-3.655b414a.69585.e84e84691cd2e05baa9eec9585016b18
You have this error because the API call you're trying (
GET /cloud/project/{project_id}/image
) is not granted for the token you generated.When you generate a token, you need to specify for which API path and HTTP verb (
GET
,POST
etc) this token needs to be granted.You can specify which API path/HTTP verb needs to be granted in two different ways:
Rights
part. It accept regex. For instance:GET
on/cloud*
curl
: create an App in https://www.ovh.com/auth/api/createApp, and grant it on the needed route with:You will find the complete documentation about API here.