当前位置:网站首页>Baidu document translation API
Baidu document translation API
2022-07-19 11:52:00 【. [email protected]】
# -*- coding: utf-8 -*-
import random,os
import json,time
import base64,http.client
import requests,urllib.parse
import shutil,datetime,hashlib
import requests
# appid_word = "26700"
# APIKey_word='qmvg400hG7k'
# secretKey_word = "VXjOm00n4D"
file='zhongwen.docx'
filetype=file.split('.')[-1]
filefrontname=file.split('.')[-2]
print(filetype)
with open(file, 'rb') as f:
wordcontent = base64.b64encode(f.read())
wordcontent = bytes.decode(wordcontent)
f.close()
time.sleep(3)
host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=qm00G7k&client_secret=VXj001114D'
response_token = requests.get(host)
token = response_token.json()['access_token']
print(token)
url = 'https://aip.baidubce.com/rpc/2.0/mt/v2/doc-translation/create?access_token=' + token
# Build request
headers = {'Content-Type': 'application/json;charset=utf-8'}
# headers = {'Content-Type': 'application/x-www-form-urlencoded'}
payload = { 'from': "zh",
'to': "en",
"domain": "general",
"input": {"content":wordcontent, "format": filetype,"filename": file,},
"output": {"filename_prefix": "new%s"%filefrontname, "formats": [filetype],}
}
# pip install yfinance==0.1.62 -i https://pypi.douban.com/simple/
r = requests.post(url=url, json=payload, headers=headers)
print(r.text)
result_id = r.json()['result']['id']
print(result_id)
time.sleep(1)
host2 = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=qmv00G7k&client_secret=VX00vy114D'
response_token2 = requests.get(host2)
token2 = response_token2.json()['access_token']
print(token)
url2 = 'https://aip.baidubce.com/rpc/2.0/mt/v2/doc-translation/query?access_token=' + token2
# q = ' Input query'; # example: hello
# Build request
headers2 = {'Content-Type': 'application/json;charset=utf-8'}
payload2 = {
"id": result_id
}
# Send request
r2 = requests.post(url2, params=payload2, headers=headers2)
result2 = r2.json()['result']['data']
# ['output']['files']['url']
# print(json.dumps(result2, indent=4, ensure_ascii=False))
print(result2)
time.sleep(5)
r3 = requests.post(url2, params=payload2, headers=headers2)
result3 = r3.json()['result']['data']['status']
print(result3)
result4 = r3.json()['result']['data']['output']['files'][0]['url']
print(result4)
版权声明
本文为[. [email protected] $]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/200/202207171506171985.html
边栏推荐
- Tiflash performance tuning
- From "passive" to "active", how can zeta technology help to upgrade "rfid2.0"?
- 02-3、指针和引用的区别
- Kernel mode and user mode
- windows10:vscode下go语言的适配
- Robot development -- robot data summary
- JVM hook hooks function
- 2022.07.13 summer training personal qualifying (VIII)
- STL string输入输出重载2
- 03-1、内联函数、auto关键字、typeid、nullptr
猜你喜欢

Send blocking, receive blocking

Kunlunbase online meetup is waiting for you~

Leetcode 1252. Number of odd value cells

Leetcode 1304. 和为零的 N 个不同整数

cv02-roge矩阵,旋转向量 ,角度

NAT technology and NAT alg

开发那些事儿:如何解决RK芯片视频处理编解码耗时很长的问题?

The underlying principle of file operation (inode and hard and soft links, time attributes of files)

Wechat applet cloud development 1 - Database

Keras deep learning practice (14) -- r-cnn target detection from scratch
随机推荐
A summary of C language pointer
Redis分布式缓存-Redis集群
Tiflash performance tuning
梦想CMS 前台搜索SQL注入
Fundamentals of scala (3): operators and process control
Huawei firewall authentication technology
JVM hook hooks function
[wechat applet] use a thousand hand float - rollback
02-2、缺省参数、函数重载、引用、隐式类型转换、关于报错
Cv02 Roge matrix, rotation vector, angle
【PostgreSQL 】PostgreSQL 15对distinct的优化
LeetCode刷题——查找和最小的 K 对数字#373#Medium
Redis distributed cache redis cluster
机器人开发--机器人资料汇总
The underlying principle of file operation (inode and hard and soft links, time attributes of files)
function/symbol ‘pango_context_set_round_glyph_positions‘ not found in library ‘libpango-1.0.so.0‘x
Unchangeable status quo
Docker安装MySQL
Developing those things: how to solve the problem of long-time encoding and decoding of RK chip video processing?
Hello JSON Schema