Doc Translation

Prev Next

Classic/VPC 환경에서 이용 가능합니다.

Papago Doc Translation API 예제를 소개합니다.

문서 번역

문서 번역 예제를 설명합니다.

Python

Python 기반의 API 예제 코드는 다음과 같습니다.

import requests
from requests_toolbelt import MultipartEncoder
import uuid

data = {
  'source': 'ko',
  'target': 'en',
  'file': ('a.docx', open('a.docx', 'rb'), 'application/octet-stream', {'Content-Transfer-Encoding': 'binary'})
}
m = MultipartEncoder(data, boundary=uuid.uuid4())

headers = {
  "Content-Type": m.content_type,
  "X-NCP-APIGW-API-KEY-ID": 유저_클라이언트_아이디,
  "X-NCP-APIGW-API-KEY": 유저_클라이언트_시크릿
}

url = "https://papago.apigw.gov-ntruss.com/doc-trans/v1/translate"
res = requests.post(url, headers=headers, data=m.to_string())
print(res.text)

문서 번역 상태 확인

문서 번역 상태 확인 예제를 설명합니다.

Python

Python 기반의 API 예제 코드는 다음과 같습니다.

import requests

headers = {
  "X-NCP-APIGW-API-KEY-ID": 유저_클라이언트_아이디,
  "X-NCP-APIGW-API-KEY": 유저_클라이언트_시크릿
}

url = "https://papago.apigw.gov-ntruss.com/doc-trans/v1/status?requestId=" + RequestId
res = requests.get(url, headers=headers)
print(res.text)

문서 번역 결과 다운로드

문서 번역 결과 다운로드 예제를 설명합니다.

Python

Python 기반의 API 예제 코드는 다음과 같습니다.

import urllib.request

url = "https://papago.apigw.gov-ntruss.com/doc-trans/v1/download?requestId=" + RequestId

opener = urllib.request.build_opener()
opener.addheaders = [('X-NCP-APIGW-API-KEY-ID', 유저_클라이언트_아이디), ('X-NCP-APIGW-API-KEY', 유저_클라이언트_시크릿)]
urllib.request.install_opener(opener)

urllib.request.urlretrieve(url, "b.docx")