Jay Taylor's notes
back to listing indexProtocol buffers python - unicode decode error
[web search]
I need to receive a protocol buffers message on my python - tornado server and get the stuff out of the binary message.
It works perfectly using a test tool. When i run it in sandbox environment and simulate 1000 requests from my client, it works in certain cases, but in most of the requests, it throws an exception -
In some other cases it gives these errors -
What could be the reason ?
|
|||||||||||||||||||||
|
|||||||||||||||||||||
I had exactly same problem with RabbitMQ and Protocol Buffers. The problem is that protocol buffer assumes the input to be of type str, whereas RabbitMQ seems to decode the message as unicode in some cases (if the byte array contains bytes greater than 127). The same may happen with Tornado as well. So far it seems, that the problem can be solved by following piece of code:
This code turns the unicode string to python bytes object, which can be happily parsed by protocol buffer messages. Dunno if there is some better way to do this, but at least this seems to work.
|
|||||||||||||||
|
Your Answer
asked |
4 years ago |
viewed |
3629 times |
active |
Related
Technology | Life / Arts | Culture / Recreation | Science | Other | ||
---|---|---|---|---|---|---|