【发布时间】:2019-06-21 20:40:18
【问题描述】:
我正在尝试使用 GCP 参考上可用的 python 脚本将文件上传到谷歌云存储,但每次运行它时,我都会收到找不到 json 密钥凭据文件的文件错误,即使它与蟒蛇脚本。
错误是:
文件“c:\users\kundan\appdata\local\programs\python\python37-
32\lib\site- packages\google\cloud\client.py”,第 75 行,在 from_service_account_json 使用 io.open(json_credentials_path, "r", encoding="utf-8") 作为 json_fi: FileNotFoundError:[Errno 2] 没有这样的文件或目录:'key.json'
代码如下:
from google.cloud import storage
def upload_blob(bucket_name, source_file_name, destination_blob_name):
storage_client = storage.Client.from_service_account_json(
'key.json')
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print('File {} uploaded to {}.'.format(
source_file_name,
destination_blob_name))
bucket='synersense_data'
source_file_name='gcp.txt'
destination_blob_name='prototype'
upload_blob(bucket,source_file_name,destination_blob_name)
【问题讨论】:
-
尝试添加
key.json文件的绝对路径。 -
同样的错误,即使我将路径指定为 'E:folder\file.json'
标签: python google-cloud-platform