请求参数
详情请见:机器批量翻译调用指南
下载安装
导入Maven依赖文件
pip install aliyun-python-sdk-core # 安装阿里云SDK核心库
pip install aliyun-python-sdk-alimt # 安装机器翻译
代码示例
#!/usr/bin/env python
#coding=utf-8
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkcore.auth.credentials import StsTokenCredential
from aliyunsdkalimt.request.v20181012.GetBatchTranslateRequest import GetBatchTranslateRequest
credentials = AccessKeyCredential('<your-access-key-id>', '<your-access-key-secret>')
# use STS Token
# credentials = StsTokenCredential('<your-access-key-id>', '<your-access-key-secret>', '<your-sts-token>')
client = AcsClient(region_id='cn-shanghai', credential=credentials)
request = GetBatchTranslateRequest()
request.set_accept_format('json')
request.set_FormatType("text")
request.set_TargetLanguage("en")
request.set_SourceLanguage("zh")
request.set_Scene("general")
request.set_ApiType("translate_standard")
request.set_SourceText(" { \"11\": \"你好\", \"12\": \"回家\", \"13\": \"我们能行\" } ")
response = client.do_action_with_exception(request)
# python2: print(response)
print(str(response, encoding='utf-8'))