2016-08-12 4 views
4

는 내가 직접 만든 양동이에 파일을 업로드하는이 튜토리얼을 다음있어 파이썬 BOTO 라이브러리 설치 서비스 계정 자격 증명 방법 : https://cloud.google.com/storage/docs/xml-api/gspythonlibrary클라우드 스토리지 :

나는 위로 설정에 문제를 갖고있는 것 같다 자격 증명은 서비스 계정 또는 사용자 계정으로 모두 있습니다. 나는 이것을 웹 서버에서 사용하고자하므로 서비스 계정으로 설정해야합니다.

콘솔에서 API 관리자를 사용하여 API를 만들고 JSON을 다운로드했습니다. 한편 내 gcloud 인증은 OAuthH 로그인으로 설정됩니다. 나는 gsutil config -e을 시도했고, 오류가있어 : 나는 또한 사용하여 서비스 계정을 인증하려고

CommandException: OAuth2 is the preferred authentication mechanism with the Cloud SDK. Run "gcloud auth login" to configure authentication, unless you want to authenticate with an HMAC access key and secret, in which case run "gsutil config -a". 

: gcloud auth activate-service-account --key-file <json file>

하지만 여전히 파이썬 BOTO에 액세스 할 수 있도록과 행운을. 나는 또한 ~/.config/gcloud/에서 ~/.boto으로 ID와 Key를 복사했으나 작동하지 않았습니다. 나는 클라우드 스토리지에 액세스하기 위해 파이썬 서버에 대한 인증을 어떻게 설정해야하는지 모르겠습니다. 저는 App Engine을 사용하지 않고 Cloud Compute를 사용하여 웹 서버를 설정합니다.

import boto 
import gcs_oauth2_boto_plugin 
import os 
import shutil 
import StringIO 
import tempfile 
import time 

CLIENT_ID = 'my client id from ~/.config/gcloud/credentials' 
CLIENT_SECRET = 'my client secret from ~/.config/gcloud/credentials' 
gcs_oauth2_boto_plugin.SetFallbackClientIdAndSecret(CLIENT_ID, CLIENT_SECRET) 

uri = boto.storage_uri('', 'gs') 
project_id = 'my-test-project-id' 
header_values = {"x-test-project-id": project_id} 
# If the default project is defined, call get_all_buckets() without arguments. 
for bucket in uri.get_all_buckets(headers=header_values): 
    print bucket.name 

가장 최근 오류 :

여기 내 소스 코드의

Traceback (most recent call last): 
    File "upload/uploader.py", line 14, in <module> 
    for bucket in uri.get_all_buckets(headers=header_values): 
    File "/Users/ankitjain/dev/metax/venv/lib/python2.7/site-packages/boto/storage_uri.py", line 574, in get_all_buckets 
    return conn.get_all_buckets(headers) 
    File "/Users/ankitjain/dev/metax/venv/lib/python2.7/site-packages/boto/s3/connection.py", line 444, in get_all_buckets 
    response.status, response.reason, body) 
boto.exception.GSResponseError: GSResponseError: 403 Forbidden 
<?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidSecurity</Code><Message>The provided security credentials are not valid.</Message><Details>Incorrect Authorization header</Details></Error> 
+0

코드 실행 위치는 어디입니까? GCE 또는 GAE에있는 경우 Google 애플리케이션 기본 자격증 명이 인증을 위해 권장되는 방법입니다. https://developers.google.com/identity/protocols/application-default-credentials – Dagang

+0

이 코드를 GCE에서 실행하고 싶지만 로컬 개발 환경도 가지고 있습니다. 설명서에 로컬 환경에서 작동하는 방법이 설명되어 있지 않습니다. – Ankit

+0

찾고 계신 것입니까? https://cloud.google.com/compute/docs/api/how-tos/authorization#gcloud_auth_login – Dagang

답변

0

좋아 내가 클라우드 스토리지에 데이터를 업로드 GCE 라이브러리를 사용하여 포기 좀 더 실험 후. 실제로 AWS boto를 사용하여 클라우드 스토리지에 업로드하는 것이 훨씬 더 효과적이라는 것을 알았습니다.

conn = boto.connect_s3(app.config['S3_KEY'], app.config['S3_SECRET'], "c.storage.googleapis.com") 
bucket = conn.get_bucket(app.config['S3_BUCKET'], validate=False) 

내가 HMAC 인증은 Google 문서 도구에 설명 된 방법을 생성 사용 : 내가해야 할 일을했을 모든 S3 도서관에서 구글의 호스트를 지정했다. 참조 : https://cloud.google.com/storage/docs/migrating

+0

잠시 기다려주십시오. 구글 키와 비밀? – frmsaul

관련 문제