구름 IDE / Python
Google Translate API 예제 깃허브 보면서 따라함
https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/translate/cloud-client/snippets.py
[1] pip install google-cloud / pip install google-cloud-translate
다음과 같은 에러 발생
Cannot uninstall ‘six’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
원인) distutils는 uninstaller가 없기 때문에 muanual로 지워줘야 한다.
해결방법1) 문제되는 패키지 삭제/이동
rm /usr/lib/python2.7/dist-packages/six*
rm /usr/lib/python3/dist-packages/six*
* 참고 링크 https://forum.technote.kr/forums/topic/%ED%95%B4%EA%B2%B0%EB%B0%A9%EB%B2%95-it-is-a-distutils-installed-project-and-thus-we-cannot-accurately/
해결방법2) 이미 인스톨된 패키지 무시하기
pip install --ignore-installed google-cloud
[2] 실행 시켜보면 Client 없다는 attributeError 발생
translate_client = translate.Client() attributeError: 'function' object has no attribute 'Client'
예제 코드를 보면 아래와 같이 import한 translate의 Client를 호출하는데
from google.cloud import translate
...
translate_client = translate.Client() |
저 호출부분을 내가 새로 만든 함수 안에 넣었다.
근데 새 함수 이름이 translate였다...import한 translate가 아닌 함수 translate 안에서 Client()를 찾았던 것.
함수 이름을 바꾸면 된다.
[3] 인증 에러
DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application.
For more information, please see https://developers.google.com/accounts/docs/application-default-credentials.
auth관련해선 gcloud init만 해둔 상태...
에러 메시지의 링크로 가서 따라하는데 인증 키를 파일로 받아서 환경변수로 경로 지정해주는 것 같았다.
Command Line으로 할 수 있다길래 해봤는데....3번 했는데 키파일이 어디에 생성된건지...현재 디렉토리에 없었다.
어디서 찾아야할지 몰라서 결국 GCP Console가서 다운받고 winscp로 구름에 원격접속해서 넣음 ㅎㅎ
(GCP Console : 사용하는 구글 클라우드 API들 관리할 수 있는 웹페이지. 대시보드 있고 사용자 등록하고 하는 곳)
인증 키 받는 부분이 몇달전이랑 좀 달라진 것 같다...좀 헤맸다 이런걸로 헤메고 있다니 ㅜㅜ
맨 위에서 프로젝트 선택하고
왼쪽에서 서비스 계정 탭
맞는 이름 찾아서 작업에 점점점 누르면 '키 만들기' 메뉴가 뜬다.
Json 파일 받아서 원하는 경로에 넣고 그 경로를 환경변수 GOOGLE_APPLICATION_CREDENTIALS에 추가한다. (에러 메시지의 링크 타고 도큐먼트 들어가면 순서대로 설명 있음)
아무튼 모든 구글 API 사용할 떄 인증하려면
1) GCP에서 프로젝트 생성하고 사용자(구글 아이디) 등록
2) gcloud init 하고 사용자 인증 (나오는 링크 타고 인증키 복붙하는 과정있음)
3) 콘솔에서 gcloud iam 이용 또는 GCP Console에서 키(json파일) 생성
4) GOOGLE_APPLICATION_CREDENTIALS에 키 파일 경로 추가
[4] language code / 구글 번역 API 언어 설정 / 한국어
한국어 : 'ko'
영어 : 'en'
ISO 639-1 language code 라고 부른다.
https://cloud.google.com/translate/docs/languages
[5] 한글로 번역했을 때 결과 인코딩?
'미분류' 카테고리의 다른 글
병행성 관련 용어 간단 정리 / 뮤텍스, 세마포어, 모니터 (0) | 2018.11.07 |
---|---|
객체지향 디자인 패턴 간략하게 정리 - 싱글턴 패턴, 팩토리 메소드 패턴, 옵저버 패턴 (0) | 2018.11.07 |
구글 드라이브 파일 다운로드가 안될 때 (1) | 2018.07.31 |
[MongoDB] MongoDB 클라이언트 터미널 명령어 정리 (0) | 2018.05.16 |
비주얼스튜디오 printf, scanf 대신 _s 붙은 함수 사용하라는 에러 (0) | 2016.07.14 |