I am new to Boto and Google Cloud Storage and am following this tutorial.
I am experiencing two problems:
1) When running the file from command line
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)
It throws an exception right at create_bucket
:
oauth2client.client.AccessTokenRefreshError: invalid_grant
I am not sure how to proceed here, considering the .boto
file exists in my home folder.
2) The other problem is the moment I run the same script within PyCharm, it crashes at importing gcs_oauth2_boto_plugin.
import boto
import gcs_oauth2_boto_plugin
ImportError: cannot import name HAS_CRYPTO
Within oauth2_client.py
there is the line
from oauth2client.client import HAS_CRYPTO
and this one seems to throw an exception. This doesn't seem to happen within the command line.
Both command line and PyCharm are using the same Virtual-env, so it's a mystery to me why it behaves differently. If you have any idea, please advice. Thanks
It works fine for me in PyCharm (4.0.3).
The only thing I can think of is to rerun:
gcloud auth login