Google cloud storage 从colab访问GCS-Python

Google cloud storage 从colab访问GCS-Python,google-cloud-storage,google-colaboratory,Google Cloud Storage,Google Colaboratory,我试图使用以下代码行从Colab访问GCS,并获得给定的错误。我错过什么了吗?或者Colab不支持这种地面军事系统访问?是否有任何变通方法或最佳实践可供我使用 from google.cloud import storage client = storage.Client() bucket = client.get_bucket('busnet_videos') blob = bucket.blob('my-test-file.txt') blob.upload_from_string('th

我试图使用以下代码行从Colab访问GCS,并获得给定的错误。我错过什么了吗?或者Colab不支持这种地面军事系统访问?是否有任何变通方法或最佳实践可供我使用

from google.cloud import storage

client = storage.Client()
bucket = client.get_bucket('busnet_videos')
blob = bucket.blob('my-test-file.txt')
blob.upload_from_string('this is test content!')
错误:

    ---------------------------------------------------------------------------

OSError                                   Traceback (most recent call last)

<ipython-input-7-0ed440d78c8f> in <module>()
      7 from google.cloud import storage
      8 
----> 9 client = storage.Client()
     10 bucket = client.get_bucket('busnet_videos')
     11 blob = bucket.blob('my-test-file.txt')

2 frames

/usr/local/lib/python3.6/dist-packages/google/cloud/storage/client.py in __init__(self, project, credentials, _http)
     71             project = None
     72         super(Client, self).__init__(
---> 73             project=project, credentials=credentials, _http=_http
     74         )
     75         if no_project:

/usr/local/lib/python3.6/dist-packages/google/cloud/client.py in __init__(self, project, credentials, _http)
    221 
    222     def __init__(self, project=None, credentials=None, _http=None):
--> 223         _ClientProjectMixin.__init__(self, project=project)
    224         Client.__init__(self, credentials=credentials, _http=_http)

/usr/local/lib/python3.6/dist-packages/google/cloud/client.py in __init__(self, project)
    176         if project is None:
    177             raise EnvironmentError(
--> 178                 "Project was not passed and could not be "
    179                 "determined from the environment."
    180             )

OSError: Project was not passed and could not be determined from the environment.
---------------------------------------------------------------------------
OSError回溯(最近一次调用上次)
在()
7从google.cloud导入存储
8.
---->9 client=storage.client()
10 bucket=client.get_bucket('busnet_videos'))
11 blob=bucket.blob('my-test-file.txt')
2帧
/usr/local/lib/python3.6/dist-packages/google/cloud/storage/client.py in_u_init__;(self,project,credentials,_http)
71项目=无
72超级(客户机,自我)初始化__(
--->73项目=项目,凭证=凭证,\u http=\u http
74         )
75如果没有项目:
/usr/local/lib/python3.6/dist-packages/google/cloud/client.py in_u______________________________
221
222定义初始化(self,project=None,credentials=None,_http=None):
-->223_ClientProjectMixin.__init__(self,project=project)
224客户端。\uuuu init\uuuuuu(self,credentials=credentials,\uhttp=\uhttp)
/usr/local/lib/python3.6/dist-packages/google/cloud/client.py in_uu__________(self,project)
176如果项目无:
177 raise环境错误(
-->178“项目未通过,无法执行”
179“由环境决定。”
180             )
OSError:项目未通过,无法从环境中确定。

您可能需要设置一个环境变量:

GOOGLE\u APPLICATION\u CREDENTIALS=SERVICE\u ACCOUNT\u KEY.json


PROJECT\u ID=YOUR\u GOOGLE\u CLOUD\u PROJECT\u ID

在实例化客户端时尝试指定您的项目ID:
client=storage.client(“您的项目ID”)
。我在电视上看到的。