【问题标题】:App Engine can't find file when deploying部署时 App Engine 找不到文件
【发布时间】:2020-10-14 13:06:51
【问题描述】:

我正在制作一个需要访问我的 Google 云存储桶中文件的应用。 我使用this 教程来访问我的文件。 该教程说您需要使用“服务帐户密钥页面”-json 文件来访问存储桶,如下所示:

storage_client= storage.Client.from_service_account_json("/home/Project/red-freedom-XXXXX-XXXXXXXXX.json")

Json 文件与 main.py 和 app.yaml 文件存储在同一文件夹中。 该程序在我本地运行时运行顺利,但是当我部署它时,我得到:

FileNotFoundError: [Errno 2] No such file or directory: "/home/Project/red-freedom-XXXXX-XXXXXXXXX.json"

我该如何解决这个问题?

【问题讨论】:

    标签: google-app-engine flask google-cloud-platform google-cloud-storage google-app-engine-python


    【解决方案1】:

    您似乎在使用基于本地文件系统的 .json 文件的绝对路径,但在 App Engine 上,这需要是不同的路径。

    相反,您可以使用您尝试在其中创建客户端的文件中的相对路径:

    import os
    
    current_directory = os.path.abspath(os.path.dirname(__file__))
    path_to_service_account_json = os.path.join(current_directory, 'red-freedom-XXXXX-XXXXXXXXX.json')
    storage_client= storage.Client.from_service_account_json(path_to_service_account_json)
    

    【讨论】:

      猜你喜欢
      • 2018-09-07
      • 1970-01-01
      • 2012-06-25
      • 2021-12-30
      • 2011-03-20
      • 2015-02-19
      • 2013-10-23
      • 2014-01-05
      • 2019-11-08
      相关资源
      最近更新 更多