Discussion:
[tornado] save gzip response from clickhouse http api
Ярик Макаров
2018-06-28 12:45:39 UTC
Permalink
Hi, I`m trying to save gzip response from clickhouse http api.
Does Tornado automatically decompress gzip-encoded responses like, for
example, requests python module?
If so, how can I disable it and get raw data?

Code example:

class GetLogHandler(tornado.web.RequestHandler):
@tornado.gen.coroutine
def get(self):
self.set_header('Accept-Encoding', 'gzip')
self.set_header('content-Disposition', 'attachment;
filename=test.gz')
self.flush()
query = "select * from test_table"
select_query = urllib.quote(query)
url = "http://localhost:8123/?enable_http_compression=1&query=%s" %
select_query
yield AsyncHTTPClient().fetch(url,
streaming_callback=self.streaming_callback, decompress_response=False)
self.finish()

def streaming_callback(self, chunk):
self.write(chunk)
self.flush()


class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r"/", GetLogHandler)
]
tornado.web.Application.__init__(self, handlers)

Thanks,
Yaroslav.
--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornado+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ben Darnell
2018-06-30 16:57:02 UTC
Permalink
I don't quite understand what you're asking. The answer to your question is
"yes, it decompresses by default, but you can pass
decompress_response=False to disable this". But you have
`decompress_response=False` in the code sample, so you've apparently
discovered this on your own. What's left? What did you expect to happen,
and what did you see instead?

Maybe you need to add an `Accept-Encoding: gzip` header to the request to
tell the server that you want compressed responses.

-Ben
Post by Ярик Макаров
Hi, I`m trying to save gzip response from clickhouse http api.
Does Tornado automatically decompress gzip-encoded responses like, for
example, requests python module?
If so, how can I disable it and get raw data?
@tornado.gen.coroutine
self.set_header('Accept-Encoding', 'gzip')
self.set_header('content-Disposition', 'attachment;
filename=test.gz')
self.flush()
query = "select * from test_table"
select_query = urllib.quote(query)
url = "http://localhost:8123/?enable_http_compression=1&query=%s"
% select_query
yield AsyncHTTPClient().fetch(url,
streaming_callback=self.streaming_callback, decompress_response=False)
self.finish()
self.write(chunk)
self.flush()
handlers = [
(r"/", GetLogHandler)
]
tornado.web.Application.__init__(self, handlers)
Thanks,
Yaroslav.
--
You received this message because you are subscribed to the Google Groups
"Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornado+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...