import cloudstorage,SyntaxError:invalid syntax

时间:2018-02-01 10:12:38

标签: python google-cloud-storage cloud-storage

我想使用Google Cloud Storage Client Library Functions

为此,我必须import cloudstorage。要获得cloudstorage我下载Google Cloud Storage client library

我尝试使用cloudstorage导入python -c "import cloudstorage"。 我收到以下错误:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/fghavamian/Documents/PhD_work/Codes/python/convnet_gcloud/cloudstorage/__init__.py", line 20, in <module>
    from .api_utils import RetryParams
  File "/Users/fghavamian/Documents/PhD_work/Codes/python/convnet_gcloud/cloudstorage/api_utils.py", line 173
    except self.retriable_exceptions, e:
                                    ^
SyntaxError: invalid syntax

我错过了什么吗?

1 个答案:

答案 0 :(得分:3)

正如评论之一所言,这是使用Python 3的一个问题,因为语法已更改。似乎您所使用的Google Cloud Storage库似乎没有得到很好的支持,并且more recommended库是google-cloud-python

假设已安装Google Cloud SDK,则可以使用以下命令安装它:

from google.cloud import storage
client = storage.Client()
# https://console.cloud.google.com/storage/browser/[bucket-id]/
bucket = client.get_bucket('bucket-id-here')
# Then do other things...
blob = bucket.get_blob('remote/path/to/file.txt')
print(blob.download_as_string())  # read content from bucket and print to stdout
blob.upload_from_string('New contents!')
blob2 = bucket.blob('remote/path/storage.txt')
blob2.upload_from_filename(filename='/local/path.txt')  # write from path.txt to storage.txt

以下是一些示例代码(from the docs),显示了如何读取和写入存储桶。

input()