OVHcloud API Client
The `ovh` Python library is the official module for interacting with OVHcloud APIs. It provides a thin wrapper that handles the complexities of credential creation and request signing. The library is currently at version 1.2.0 and is actively maintained, with new releases incorporating features and compatibility updates for modern Python versions. It is designed to simplify automation and management of OVHcloud services.
Common errors
-
TypeError: {'my_param': 'value'} is not JSON serializablecause Attempting to manually `json.dumps()` a Python dictionary when passing it as a parameter to `client.post()` or `client.put()`.fixPass the dictionary or keyword arguments directly to the method: `client.post('/path', param1='value1', param2='value2')` or `client.post('/path', **my_dict_params)`. -
ovh.exceptions.APIError: 403 Forbidden - Invalid signature
cause Incorrect `application_secret` or `consumer_key`, a timestamp skew between your system and the API, or the consumer key lacking necessary permissions for the requested API endpoint.fixDouble-check your `application_secret` and `consumer_key`. Ensure your system's clock is synchronized. Verify that the `consumer_key` has the required access rights for the API path you are trying to call. Refer to `https://api.ovh.com/createToken/` to review and generate credentials. -
ovh.exceptions.APIError: 400 Bad Request - Low HTTP request failed error
cause General misconfiguration of the client, such as an incorrect `endpoint` or missing required authentication parameters.fixVerify that your `endpoint` (e.g., 'ovh-eu') is correct. Ensure all required authentication parameters (`application_key`, `application_secret`, `consumer_key`) are provided and valid, either in code, `ovh.conf`, or environment variables.
Warnings
- breaking Version 1.0.0 and later of `python-ovh` dropped support for Python 2.7, 3.4, and 3.5. Users running these older Python versions must use `python-ovh` version 0.6.x or earlier.
- gotcha When making `POST` or `PUT` requests, the Python client automatically serializes parameters to JSON. Do NOT manually use `json.dumps()` on your payload, as this will lead to a `TypeError` or an `Invalid JSON object` error.
- gotcha Embedding API keys directly in your code is a security risk and lacks flexibility. OVHcloud recommends using configuration files (`ovh.conf`) or environment variables for managing credentials across different environments (e.g., development, production).
- gotcha The `consumer_key` (CK) is specific to an application *and* a user account. It is obtained through a 3-step OAuth-like process involving requesting a new CK, redirecting the user to a validation URL, and the user authenticating to grant access. A hardcoded CK will only work if pre-authorized.
Install
-
pip install ovh
Imports
- Client
import ovh client = ovh.Client(...)
Quickstart
import os
import ovh
# Best practice: load credentials from environment variables or ovh.conf
# Alternatively, embed directly (less recommended for production)
endpoint = os.environ.get('OVH_ENDPOINT', 'ovh-eu') # e.g., 'ovh-eu', 'ovh-ca'
application_key = os.environ.get('OVH_APPLICATION_KEY', 'YOUR_APP_KEY')
application_secret = os.environ.get('OVH_APPLICATION_SECRET', 'YOUR_APP_SECRET')
consumer_key = os.environ.get('OVH_CONSUMER_KEY', 'YOUR_CONSUMER_KEY')
try:
client = ovh.Client(
endpoint=endpoint,
application_key=application_key,
application_secret=application_secret,
consumer_key=consumer_key,
)
# Example: Get current user details
me = client.get('/me')
print(f"Hello, {me['firstname']} {me['lastname']}!")
# Example: List your dedicated servers (requires appropriate rights)
# servers = client.get('/dedicated/server')
# print(f"Your dedicated servers: {servers}")
except ovh.exceptions.APIError as e:
print(f"API Error: {e.code} - {e.message}")
except Exception as e:
print(f"An unexpected error occurred: {e}")