如何设置oauth2\u客户端的访问权限?

2024-05-08 22:32:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Boto和Google云存储的新手,正在关注这个tutorial。你知道吗

我遇到两个问题:

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)

它在create_bucket处抛出异常:

oauth2client.client.AccessTokenRefreshError: invalid_grant

考虑到我的主文件夹中存在.boto文件,我不确定如何继续。你知道吗

2)另一个问题是,当我在PyCharm中运行相同的脚本时,它在导入gcs\u oauth2\u boto\u插件时崩溃。你知道吗

import boto
import gcs_oauth2_boto_plugin

ImportError: cannot import name HAS_CRYPTO

oauth2_client.py中有一行

from oauth2client.client import HAS_CRYPTO

而这一个似乎抛出了一个例外。这似乎不会发生在命令行中。你知道吗

命令行和PyCharm都使用同一个虚拟env,所以为什么它的行为不同对我来说是个谜。如果你有什么想法,请指教。谢谢


Tags: the命令行importprojectclientidforbucket