"네이버 번역 API"의 두 판 사이의 차이

(새 문서: ==개요== ;네이버 번역 API <syntaxhighlight lang='python'> # 네이버 기계번역 API 예제 import os import sys import urllib.request client_id = "VhjlnXZ6B81pDF0H2J4r" # F...)
 
37번째 줄: 37번째 줄:


[[분류: 네이버]]
[[분류: 네이버]]
[[분류: 기계번역]]
[[분류: API]]
[[분류: API]]

2021년 1월 4일 (월) 22:06 판

1 개요

네이버 번역 API
# 네이버 기계번역 API 예제
import os
import sys
import urllib.request
client_id = "VhjlnXZ6B81pDF0H2J4r" # Fake
client_secret = "sSuwUyaWYB" # Fake
encText = urllib.parse.quote("번역할 문장을 입력하세요")
data = "source=ko&target=en&text=" + encText
#url = "https://openapi.naver.com/v1/language/translate" # 404
url = "https://openapi.naver.com/v1/papago/n2mt"
request = urllib.request.Request(url)
request.add_header("X-Naver-Client-Id",client_id)
request.add_header("X-Naver-Client-Secret",client_secret)
response = urllib.request.urlopen(request, data=data.encode("utf-8"))
rescode = response.getcode()
if(rescode==200):
    response_body = response.read()
    print(response_body.decode('utf-8'))
else:
    print("Error Code:" + rescode)
testuser@localhost:~$ python a.py
{"message":{"@type":"response","@service":"naverservice.nmt.proxy","@version":"1.0.0","result,"engineType":"N2MT","pivot":null}}}

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}