简体   繁体   English

使用Google App Engine创建大型.csv(或任何其他类型!)文件

[英]Create a large .csv (or any other type!) file with google app engine

I've been struggling to create a file with GAE for two days now, I've examined different approaches and each one seems more complex and time consuming than the previous one. 我一直在努力用GAE创建文件两天,我研究了不同的方法,每种方法似乎比以前的方法更复杂,更耗时。

I've tried simply loading a page and writing the file in to response object with relevant headers: 我试过简单地加载页面并将文件写入具有相关标题的响应对象中:

self.response.headers['Content-Disposition'] = "attachment; filename=titles.csv"
q = MyObject.all()
for obj in q:
    title = json.loads(obj.data).get('title')
    self.response.out.write(title.encode('utf8')+"\n")

This tells me (in a very long error) that Full proto too large to save, cleared variables. 这告诉我(很长的错误) Full proto too large to save, cleared variables. Here's the full error . 这是完整的错误

I've also checked Cloud Storage, but it needs tons of info and tweaking in the Cloud Console just to get enabled, and Blobstorage which can save stuff only in to the DataStore. 我还检查了Cloud Storage,但它需要大量信息并需要在Cloud Console中进行调整才能启用,而Blobstorage只能将内容保存到DataStore中。

Writing a file can't be this complicated! 编写文件不会那么复杂! Please tell me that I am missing something. 请告诉我,我缺少什么。

That error doesn't have anything to do with writing a CSV, but appears to be a timeout when iterating over all MyObject entities. 该错误与编写CSV无关,但在遍历所有MyObject实体时似乎是超时。 Remember that requests in GAE are subject to strict limits, and you are probably exceeding those. 请记住,GAE中的请求受到严格的限制,您可能超出了这些限制。 You probably want to use a cursor and the deferred API to build up your CSV in stages. 您可能想使用游标和延迟的API分阶段构建CSV。 But for that, you definitely will need to write to the blobstore or CS. 但是为此,您肯定需要写入blobstore或CS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM