【发布时间】:2021-06-22 21:28:52
【问题描述】:
FileNotFoundError 尝试通过引用gs://BUCKET_NAME/FolderName/ 读取/访问存在于谷歌云存储桶中的文件或文件夹时。
我使用 python 3 作为带有 jupyter notebook 的内核。我在链接到存储桶的谷歌云中配置了一个集群。当我尝试读取/上传文件时,我收到文件未找到错误
def get_files(bucketName):
files = [f for f in listdir(localFolder) if
isfile(join(localFolder, f))]
for file in files:
print("file path:", file)
get_files("agriculture-bucket-gl")
我应该能够访问文件夹内容或引用存储桶中任何文件夹中存在的任何文件。
错误信息:
FileNotFoundError: [Errno 2] No such file or directory: 'gs://agriculture-bucket-gl/Data sets/'
【问题讨论】:
-
缺少一些代码。你是怎么得到你的文件的?如果硬编码路径,是否还有问题?
-
是的,我正在对路径进行硬编码,但问题仍然存在。例如:localFolder = "gs://agriculture-bucket-gl/Data sets/'
-
当你从不使用
bucketName作为参数时,为什么要传递它? -
当您在名为
gs://mybucket/file.txt的文件上调用open()时,open()函数不会神奇地知道gs://前缀的意思是“从亚马逊存储桶获取此文件”;它只是认为这是一个普通的文件名,当然不是。
标签: python google-cloud-platform google-cloud-storage