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

查看:94
本文介绍了用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天全站免登陆