← 首页 | 快速使用(English) | 客户端与凭证 →
- Python >= 3.x
你可以使用 pip
来安装你的依赖。
$ pip install alibabacloud-imagesearch20200212
在您开始之前,您需要注册阿里云帐户并获取您的凭证。 SDK 使用 credentials 来管理凭证。
from alibabacloud_imagesearch20200212.client import Client
from alibabacloud_imagesearch20200212.models import SearchImageByPicAdvanceRequest
from alibabacloud_oss_util.models import RuntimeOptions
from alibabacloud_tea_rpc.models import Config
'''图像搜索示例'''
with open('pic.jpg', 'rb') as f:
# 初始化Request
request = SearchImageByPicAdvanceRequest(
instance_name='name',
pic_content_object=f
)
# 初始化Config
config = Config(
access_key_id='<your_accsee_key_id>',
access_key_secret='<your_access_key_secret>',
endpoint='<your_endpoint>',
region_id='cn-shanghai',
type='access_key'
)
# 初始化RuntimeObject
runtime_option = RuntimeOptions()
# 初始化Client
client = Client(config)
# 调用api
response = client.search_image_by_pic_advance(request, runtime_option)
print(response)
print('request id:', response.request_id)
print('code:', response.code)
print('message:', response.msg)
# head
print('docs return:', response.head.docs_return)
print('docs found:', response.head.docs_found)
print('search time:', response.head.search_time)
# pic info
print('category id:', response.pic_info.category_id)
print('region:', response.pic_info.region)
print('all categories:', response.pic_info.all_categories)
# Auctions
for aut in response.auctions:
print('category id:', aut.category_id)
print('product id:', aut.product_id)
'''Config'''
class Config(TeaModel):
def __init__(self):
self.access_key_id = access_key_id # access key id
self.access_key_secret = access_key_secret # access key secret
self.security_token = security_token # Security Token
self.protocol = protocol # 请求协议 http|https
self.region_id = region_id # 区域id
self.read_timeout = read_timeout # 读超时
self.connect_timeout = connect_timeout # 连接超时
self.http_proxy = http_proxy # http代理
self.https_proxy = https_proxy # https代理
self.endpoint = endpoint # endpoint
self.no_proxy = no_proxy # 代理白名单
self.max_idle_conns = max_idle_conns # 最大连接数
self.user_agent = user_agent # User-Agent
self.socks_5proxy = socks_5proxy # socks5代理
self.socks_5net_work = socks_5net_work # socks5代理协议
self.endpoint_type = endpoint_type # 域名类型:internal,accelerate 或不填
self.open_platform_endpoint = open_platform_endpoint # 文件上传时授权使用的域名(目前暂不需要填写)
self.type = type # 凭证类型,如有疑问请参考https://github.com/aliyun/credentials-python/blob/master/README-CN.md
'''RuntimeOptions'''
class RuntimeOptions(TeaModel):
def __init__(self):
self.autoretry = autoretry # 是否开启重试
self.ignore_ssl = ignore_ssl # 是否忽略 SSL 校验
self.max_attempts = max_attempts # 最大重试次数, 默认为 3
self.backoff_policy = backoff_policy # 重试休眠策略,默认为 no
self.backoff_period = backoff_period # 重试休眠时间, 默认为 1
self.read_timeout = read_timeout # 读超时
self.connect_timeout = connect_timeout # 连接超时
self.local_addr = local_addr # 本地网卡 ip
self.http_proxy = http_proxy # http 的代理
self.https_proxy = https_proxy # https 的代理
self.no_proxy = no_proxy # 代理白名单
self.max_idle_conns = max_idle_conns # 最大连接数
self.socks_5proxy = socks_5proxy # socks5 代理
self.socks_5net_work = socks_5net_work # socks5 代理协议