【问题标题】:"IOError: [Errno 30] Read-only file system" error in Google App EngineGoogle App Engine 中的“IOError:[Errno 30] 只读文件系统”错误
【发布时间】:2018-04-09 01:39:29
【问题描述】:

我在 Flask 中有一个函数,它执行一些网页抓取并将内容放入 HTML 文件中。

@app.route('/something')
def something():
    web_scraping()
    return render_template('myFile.html')

web_scraping 函数将一些 HTML 代码输出到myFile.html,当我在本地运行它时效果很好,但是当我把它放在 Google App Engine 上时,我得到了这个错误:

IOError: [Errno 30] Read-only file system: 'templates/myFile.html'

【问题讨论】:

    标签: python google-app-engine flask ioerror


    【解决方案1】:

    You cannot write to the file system

    为什么我不能写入这个文件?

    App Engine 不支持写入本地文件,因为 应用程序的分布式特性。相反,必须是 持久化应该存储在分布式数据存储中。更多 信息请参阅运行时沙箱上的文档

    但是,你仍然可以写文件:

    在 App Engine 中,您的应用程序所部署的本地文件系统 to 是不可写的。这种行为确保了安全性和 应用程序的可扩展性。

    但是,如果应用程序需要在运行时读写文件, App Engine 提供了内置的 Google Cloud Storage 流包装器 允许您使用许多标准的 PHP 文件系统函数 在 App Engine PHP 应用程序中读取和写入文件。

    【讨论】:

    • /tmp 解决方案就像一个魅力。最重要的是使用os.remove 函数在工作完成后立即删除文件。(或您的语言中的等效项。)
    • 只需使用您的常规云文件库并编写类似fhandler.write("\tmp\{}".format(<your_file_name>)) 的内容,然后完全擦除所有文件和目录。检查此链接:cloud.google.com/appengine/docs/standard/python3/…@DarrenZou
    猜你喜欢
    • 2018-10-05
    • 2022-11-23
    • 1970-01-01
    • 2021-11-19
    • 2020-07-01
    • 2020-05-19
    • 2022-06-23
    • 1970-01-01
    • 2013-06-19
    相关资源
    最近更新 更多