Boto 및 Google Cloud Storage를 처음 사용하며 다음과 같이 표시됩니다 (tutorial). 바로 create_bucket
에서 명령 줄에서 파일을 실행하면oauth2_client에 대한 액세스 권한을 설정하는 방법은 무엇입니까?
1)
GOOGLE_STORAGE = 'gs'
# URI scheme for accessing local files.
LOCAL_FILE = 'file'
# Fallback logic. In https://console.developers.google.com
# under Credentials, create a new client ID for an installed application.
# Required only if you have not configured client ID/secret in
# the .boto file or as environment variables.
CLIENT_ID = 'your client id'
CLIENT_SECRET = 'your client secret'
gcs_oauth2_boto_plugin.SetFallbackClientIdAndSecret(CLIENT_ID, CLIENT_SECRET)
now = time.time()
CATS_BUCKET = 'cats-%d' % now
DOGS_BUCKET = 'dogs-%d' % now
# Your project ID can be found at https://console.developers.google.com/
# If there is no domain for your project, then project_id = 'YOUR_PROJECT'
project_id = 'ixxx-prod'
for name in (CATS_BUCKET, DOGS_BUCKET):
# Instantiate a BucketStorageUri object.
uri = boto.storage_uri(name, GOOGLE_STORAGE)
# Try to create the bucket.
try:
# If the default project is defined,
# you do not need the headers.
# Just call: uri.create_bucket()
header_values = {"x-goog-project-id": project_id}
uri.create_bucket(headers=header_values)
그것은 예외가 발생합니다 :
나는 두 가지 문제가 발생하고
oauth2client.client.AccessTokenRefreshError: invalid_grant
나는 어떻게 확실하지 않다 내 홈 폴더에 파일이있는 것으로 간주하여 여기로 진행하십시오.
2) 다른 문제는 PyCharm 내에서 동일한 스크립트를 실행하는 순간 gcs_oauth2_boto_plugin을 가져올 때 충돌합니다. oauth2_client.py
내
ImportError: cannot import name HAS_CRYPTO
import boto
import gcs_oauth2_boto_plugin
라인
from oauth2client.client import HAS_CRYPTO
가이 하나의 예외를 던질 것으로 보인다. 이것은 명령 행에서 발생하지 않는 것 같습니다.
명령 줄과 PyCharm은 모두 동일한 Virtual-env를 사용하므로 다른 방식으로 동작하는 이유는 신비입니다. 아이디어가 있으면 조언을 구하십시오. 감사합니다