【发布时间】:2017-06-20 05:25:59
【问题描述】:
我想将 gzip 压缩数据从 tornado 服务器发送到 javascript 客户端。这是我的代码。
buf = StringIO()
gfile = gzip.GzipFile(mode='wb', fileobj=buf)
try:
gfile.write( "hello world" )
finally:
gfile.close()
compressed_data = buf.getvalue()
self.write_message( compressed_data )
服务器端不提供错误。但是 chrome 会产生错误“无法将文本帧解码为 UTF8”。
这里有什么解决方法吗?
【问题讨论】:
-
你设置了哪些标题?
-
我也尝试设置标头,但 Websockets 需要标头吗?这是我在搜索时找到的链接。 link
-
我猜你的客户需要一个使用 utf-8 的子协议。
-
客户端将数据解释为 utf-8 编码文本,因此无法解码。您需要指定适当的 MIME 类型:
application/gzip。
标签: javascript python websocket tornado