使用 Python 在 App Engine 上读取文件? [英] Read a file on App Engine with Python?

查看:18
本文介绍了使用 Python 在 App Engine 上读取文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 GAE 上打开文件只是为了读取其内容并获取最后修改的标签?

我收到一个 IOError: [Errno 13] 文件无法访问:我知道我不能删除或更新,但我相信阅读应该是可能的有没有人遇到过类似的问题?

os.stat(f,'r').st_mtim

解决方案

您可能已经在 app.yaml 中将该文件声明为静态文件.静态文件对您的应用程序不可用;如果您需要将它们作为静态文件提供并作为应用程序文件读取它们,则需要在项目中包含 2 个副本(最好使用符号链接,因此您实际上不必维护实际副本.)

2014 年 11 月更新:

正如评论中所建议的,您现在可以使用 application_readable 标志执行此操作:

application_readable

<块引用>

可选.默认情况下,静态文件处理程序中声明的文件是作为静态数据上传,只提供给最终用户,他们不能由应用程序读取.如果此字段设置为 true,则文件为还作为代码数据上传,以便您的应用程序可以读取它们.两个都上传是针对您的代码和静态数据存储资源收费的配额.

请参阅https://cloud.google.com/appengine/docs/python/config/appconfig#Static_Directory_Handlers

Is it possible to open a file on GAE just to read its contents and get the last modified tag?

I get a IOError: [Errno 13] file not accessible: I know that i cannot delete or update but i believe reading should be possible Has anyone faced a similar problem?

os.stat(f,'r').st_mtim

解决方案

You've probably declared the file as static in app.yaml. Static files are not available to your application; if you need to serve them both as static files and read them as application files, you'll need to include 2 copies in your project (ideally using symlinks, so you don't actually have to maintain an actual copy.)

Update Nov 2014:

As suggested in the comments, you can now do this with the application_readable flag:

application_readable

Optional. By default, files declared in static file handlers are uploaded as static data and are only served to end users, they cannot be read by an application. If this field is set to true, the files are also uploaded as code data so your application can read them. Both uploads are charged against your code and static data storage resource quotas.

See https://cloud.google.com/appengine/docs/python/config/appconfig#Static_Directory_Handlers

这篇关于使用 Python 在 App Engine 上读取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆