Google App Engine, How to make native file object?

2019-03-02 02:24发布

I'm trying to convert some data got from urlfetch to native python file object. Does anyone know how to do this?

I understand GAE can't save files to local. But I need file object due to library's specification.

2条回答
我想做一个坏孩纸
2楼-- · 2019-03-02 02:31

You can use python's StringIO class to wrap a a file-like object around any data retrieved by URL Fetch.

If you use python's urllib2.urlopen() instead of Google's URL Fetch API, you'll get a file-like object which might work with your library.

查看更多
闹够了就滚
3楼-- · 2019-03-02 02:45

If you just need a file-like object, you can use urllib2, which on GAE is a wrapper around urlfetch. urlopen returns the file-like object. I don't know of a way you could get a true file handle for a downloaded URL.

查看更多
登录 后发表回答