更新时间:2025-09-18 GMT+08:00
Python3语言API示例
本示例以图像标签为例介绍如何使用Python3调用API。
# encoding:utf-8
import requests
import base64
url = "https://{endpoint}/v2/{project_id}/image/tagging"
token = "用户获取得到的实际token值"
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") # 使用图片的base64编码
data= {"image": image_base64} # url与image参数二选一
response = requests.post(url, headers=headers, json=data, verify=False)
print(response.text)
|
参数 |
参数说明 |
|---|---|
|
url |
API请求URL,例如本示例中https://{endpoint}/v2/{project_id}/image/tagging。 |
|
token |
Token是用户的访问令牌,承载了用户的身份、权限等信息,用户调用API接口时,需要使用Token进行鉴权。 获取Token方法请参见。 |
|
imagePath |
图片路径。支持图片文件路径或图片url路径。其中,图片的url路径支持公网http/https url或OBS提供的url。 |
父主题: 应用示例