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) print(response.text)
Parameter |
Description |
---|---|
url |
API request URL, for example, https://{endpoint}/v1.0/image/tagging. |
token |
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 . |
imagePath |
Image path. An image file path or image URL is supported. The URL can be an HTTP/HTTPS or OBS URL. |
Feedback
Was this page helpful?
Provide feedbackFor any further questions, feel free to contact us through the chatbot.
Chatbot