如何在appengine中使用任务队列Python API传递压缩数据?

2024-04-29 11:47:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试对任务队列中的任务使用压缩数据,如下所示:

t = taskqueue.Task(url='/tasks/queue',
                   params={'param': zlib.compress(some_string)}

但是当我试图在队列处理程序中解压时

^{pr2}$

我得到这个错误:

UnicodeEncodeError: 'ascii' codec can't encode character u'\u06b8' in position 2: ordinal not in range(128)

有人知道这里发生了什么事吗?附近有工作吗?在


Tags: 数据inurl处理程序taskstringparam队列
2条回答

不要使用params,而是使用payload(未编码的请求主体中包含您的数据)。然后可以使用zlib.decompress(self.request.body)来检索数据。在

阅读the docs。。。(我的重点!)公司名称:

params Dictionary of parameters to use for this Task. Values in the dictionary may be iterable to indicate repeated parameters. May not be specified for a POST request if payload is already specified. For POST requests, these params will be encoded as 'application/x-www-form-urlencoded' and set to the payload; for all other methods, the parameters will be converted to a query string. May not be specified if the URL already contains a query string and the method is GET.

zlib.compress生成任意字节字符串。。。但是查询字符串转换将其解释为Unicode!因此,使用任何1字节的编解码器,例如latin-1,来.encode压缩结果,以便通过params的bytestring传递(实际上是二进制文件).decode的相同编解码器从“unicode”字符串返回到可以decompress的字节字符串。呜。。。你确定压缩对你的应用程序的性能来说是非常重要的,值得你做这一系列奇怪的旋转,或者避免它不是更好吗?-)在

相关问题 更多 >