–– coding: utf-8 ––
This file is auto-generated, don’t edit it. Thanks.
import sys
from typing import List
from alibabacloud_ocr_api20210707.client import Client as ocr_api20210707Client from alibabacloud_tea_openapi import models as open_api_models from alibabacloud_ocr_api20210707 import models as ocr_api_20210707_models from alibabacloud_tea_util import models as util_models from alibabacloud_tea_util.client import Client as UtilClient
class Sample: def init(self): pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> ocr_api20210707Client:
"""
使用AK&SK初始化账号Client
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
# 必填,您的 AccessKey ID,
access_key_id=access_key_id,
# 必填,您的 AccessKey Secret,
access_key_secret=access_key_secret
)
# 访问的域名
config.endpoint = f'ocr-api.cn-hangzhou.aliyuncs.com'
return ocr_api20210707Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
# 工程代码泄露可能会导致AccessKey泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378659.html
client = Sample.create_client('accessKeyId', 'accessKeySecret')
recognize_advanced_request = ocr_api_20210707_models.RecognizeAdvancedRequest()
runtime = util_models.RuntimeOptions()
try:
# 复制代码运行请自行打印 API 的返回值
client.recognize_advanced_with_options(recognize_advanced_request, runtime)
except Exception as error:
# 如有需要,请打印 error
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
# 工程代码泄露可能会导致AccessKey泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378659.html
client = Sample.create_client('accessKeyId', 'accessKeySecret')
recognize_advanced_request = ocr_api_20210707_models.RecognizeAdvancedRequest()
runtime = util_models.RuntimeOptions()
try:
# 复制代码运行请自行打印 API 的返回值
await client.recognize_advanced_with_options_async(recognize_advanced_request, runtime)
except Exception as error:
# 如有需要,请打印 error
UtilClient.assert_as_string(error.message)
if name == ‘main‘: Sample.main(sys.argv[1:])
################################################### 你好,我想问下,python调用接口,Sample.main() 函数,会return 文字识别的结果吗? 我试了一次为:Norn。 我该如何设置呢?
可以在这里return识别结果 ,此回答整理自钉群“【官方】阿里云OCR公共云客户交流群”