Updated on 2022-02-22 GMT+08:00

Python 3 API Example

This section uses Image Tagging as an example to describe how to call Python 3 APIs.

# encoding:utf-8

import requests
import base64

url = "https://{endpoint}/v1.0/image/tagging"
token = "Actual token value obtained by the user"
headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}

imagepath = r'data/image-tagging.jpg'
with open(imagepath, "rb") as bin_data:
    image_data = bin_data.read()
image_base64 = base64.b64encode(image_data).decode("utf-8")  # Use Base64 encoding of images.
data= {"image": image_base64]}  # Set either the URL or the image.

response = requests.post(url, headers=headers, json=data, verify=False)
Table 1 Parameter description




API request URL, for example, https://{endpoint}/v1.0/image/tagging.


A token is a user's access credential, which includes user identities and permissions. When you call an API to access a cloud service, a token is required for identity authentication.

For details about how to obtain the token, see Authentication.


Image path. An image file path or image URL is supported. The URL can be an HTTP/HTTPS or OBS URL.