阿里云AI接口调用

Posted AI 菌

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了阿里云AI接口调用相关的知识,希望对你有一定的参考价值。

一、图像识别服务

二、python接口调用

  • 环境安装
pip install alibabacloud_imagerecog20190930
  • 接口调用
# -*- coding: utf-8 -*-

from alibabacloud_imagerecog20190930.client import Client
from alibabacloud_imagerecog20190930.models import RecognizeLogoRequestTasks, RecognizeLogoRequest
from alibabacloud_tea_openapi.models import Config
from alibabacloud_tea_util.models import RuntimeOptions

config = Config(
  # "YOUR_ACCESS_KEY_ID", "YOUR_ACCESS_KEY_SECRET" 的生成请参考https://help.aliyun.com/document_detail/175144.html
  # 如果您是用的子账号AccessKey,还需要为子账号授予权限AliyunVIAPIFullAccess,请参考https://help.aliyun.com/document_detail/145025.html
  # 您的 AccessKey ID
  access_key_id='YOUR_ACCESS_KEY_ID',
  # 您的 AccessKey Secret
  access_key_secret='YOUR_ACCESS_KEY_SECRET',
  # 访问的域名
  endpoint='imagerecog.cn-shanghai.aliyuncs.com',
  # 访问的域名对应的region
  region_id='cn-shanghai'
)
tasks_0 = RecognizeLogoRequestTasks(
   image_url='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/RecognizeLogo/RecognizeLogo3.jpg'
)
tasks_1 = RecognizeLogoRequestTasks(
    image_url='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imagerecog/RecognizeLogo/RecognizeLogo4.jpg'
)
recognize_logo_request = RecognizeLogoRequest(
   tasks=[
     tasks_0,
     tasks_1
   ]
)
runtime = RuntimeOptions()
try:
  # 初始化Client
  client = Client(config)
  response = client.recognize_logo_with_options(recognize_logo_request, runtime)
  # 获取整体结果
  print(response.body)
except Exception as error:
  # 获取整体报错信息
  print(error)
  # 获取单个字段
  print(error.code)
  # tips: 可通过error.__dict__查看属性名称

输出结果:

三、报错问题解决

报错提示:

AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'

处理方法:

sudo apt remove python3-pip 
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py

参考方案:https://stackoverflow.com/questions/73830524/attributeerror-module-lib-has-no-attribute-x509-v-flag-cb-issuer-check

以上是关于阿里云AI接口调用的主要内容,如果未能解决你的问题,请参考以下文章

各位大神,Python怎么调用阿里云API

各位大神,Python怎么调用阿里云API

云计算:市场蓬勃发展持续扩张

阿里云有python认证吗

[python][工具]阿里云平台短信验证功能

[python][工具]阿里云平台短信验证功能