Python 谷歌应用引擎urlfetch gzip到字符串
使用GoogleAppEngine,我试图从包含一个csv文件的URL获取一个gzip文件 最后,我想在我的网页上输出csv文件的内容 我目前有以下代码:Python 谷歌应用引擎urlfetch gzip到字符串,python,google-app-engine,gzip,Python,Google App Engine,Gzip,使用GoogleAppEngine,我试图从包含一个csv文件的URL获取一个gzip文件 最后,我想在我的网页上输出csv文件的内容 我目前有以下代码: #!/usr/bin/env python import webapp2 from google.appengine.api import urlfetch class Test(webapp2.RequestHandler): def get(self): self.response.headers['Content-Typ
#!/usr/bin/env python
import webapp2
from google.appengine.api import urlfetch
class Test(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
url = *this_is_my_url*
test = urlfetch.fetch(url, deadline=25)
self.response.out.write(test.content)
app = webapp2.WSGIApplication([
('/test', Test)
], debug=True)
它要求我在本地下载文件,而不是将文件内容打印到屏幕上。如何停止本地下载,而直接打印到屏幕/网页上?看看这是否有效
#!/usr/bin/env python
import webapp2
from google.appengine.api import urlfetch
import gzip
import StringIO
class Test(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
url = *this_is_my_url*
test = urlfetch.fetch(url, deadline=25)
f = StringIO.StringIO(test.content)
c = gzip.GzipFile(fileobj=f)
content = c.read()
self.response.out.write(content)
app = webapp2.WSGIApplication([
(r'/', Test)
], debug=True)
看看这是否有效
#!/usr/bin/env python
import webapp2
from google.appengine.api import urlfetch
import gzip
import StringIO
class Test(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
url = *this_is_my_url*
test = urlfetch.fetch(url, deadline=25)
f = StringIO.StringIO(test.content)
c = gzip.GzipFile(fileobj=f)
content = c.read()
self.response.out.write(content)
app = webapp2.WSGIApplication([
(r'/', Test)
], debug=True)
在我看来,这是一个配置错误的浏览器,请尝试使用其他浏览器。您可能希望尝试添加
内容配置:inline
标题,尽管理论上不需要。我已经尝试使用Firefox,Google Chrome和Internet Explorer都下载了文件,而不是打印到屏幕上。我将其中一行改为:test=urlfetch.fetch(url,headers={'Content-disposition':'inline'},deadline=25),它现在打印到屏幕上,但它是GobbleDeBook。。。下载文件时,内容很好,但打印时,内容是这样的:o�@���+?� ����%UU)q[�谢谢您的快速回复和评论!我忘了提到我还必须编辑内容类型行以获得写入屏幕的响应。对于我来说,这看起来像是配置错误的浏览器,请尝试使用其他浏览器。您可能需要尝试添加内容配置:inline
标题,尽管理论上不需要这样做我试过Firefox、Google Chrome和Internet Explorer,每种浏览器都下载了文件,而不是打印到屏幕上。我把一行改为:test=urlfetch.fetch(url,headers={'Content-disposition':'inline'},deadline=25)它现在打印到屏幕上,但它是GobbleDeBook…下载文件时,内容很好,但打印时,内容是这样的:o�@���+?� ����%UU)q[�谢谢你的快速回复和评论!我忘了提到我还必须编辑内容类型行,以便将回复写到屏幕上。你是超级明星简!这非常有效。非常感谢。你是超级明星简!这非常有效。非常感谢。