在GAE中从urlfetch打开一个文件 [英] Open a file from urlfetch in GAE

查看:93
本文介绍了在GAE中从urlfetch打开一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在GAE中打开一个文件,该文件使用 urlfetch()获取。

到目前为止:

  from google.appengine.api import urlfetch 

result = urlfetch。 fetch('http://example.com/test.txt')
data = result.content
## f = open(...)< - 这是什么?

这看起来很奇怪,但BlobStore中有一个非常相似的可以将 data 写入BLOB文件:

  f = files.blobstore。使用files.open(f,'a')作为数据创建(mime_type ='txt',_blobinfo_uploaded_filename ='test')

data.write(result.content)

如何将 data 写入任意文件对象?



编辑:应该更清楚;我试图urlfetch 任何文件并在文件对象中打开 result.content 。所以它可能是一个.doc而不是.txt

解决方案

Yoy不必打开文件。您已收到data = result.content中的txt数据。


I'm trying to open a file in GAE that was retrieved using urlfetch().

Here's what I have so far:

from google.appengine.api import urlfetch

result = urlfetch.fetch('http://example.com/test.txt')
data = result.content
## f = open(...) <- what goes in here?

This might seem strange but there's a very similar function in the BlobStore that can write data to a blobfile:

f = files.blobstore.create(mime_type='txt', _blobinfo_uploaded_filename='test')
with files.open(f, 'a') as data:
    data.write(result.content)

How can I write data into an arbitrary file object?

Edit: Should've been more clear; I'm trying to urlfetch any file and open result.content in a file object. So it might be a .doc instead of a .txt

解决方案

Yoy do not have to open a file. You have received the txt data in data = result.content.

这篇关于在GAE中从urlfetch打开一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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