Python txZMQ从0.7.0升级到0.7.3=>;异常。UnicodeDecodeError
以下代码适用于txZMQ 0.7.0,但在txZMQ 0.7.3中中断。有什么问题吗?这是txZMQ中的错误吗 以下是测试代码:Python txZMQ从0.7.0升级到0.7.3=>;异常。UnicodeDecodeError,python,twisted,zeromq,Python,Twisted,Zeromq,以下代码适用于txZMQ 0.7.0,但在txZMQ 0.7.3中中断。有什么问题吗?这是txZMQ中的错误吗 以下是测试代码: #!/usr/bin/env python from twisted.internet import reactor from txzmq import ZmqEndpoint, ZmqFactory, ZmqPubConnection import msgpack zf = ZmqFactory() e = ZmqEndpoint('bind', 'tcp:
#!/usr/bin/env python
from twisted.internet import reactor
from txzmq import ZmqEndpoint, ZmqFactory, ZmqPubConnection
import msgpack
zf = ZmqFactory()
e = ZmqEndpoint('bind', 'tcp://*:5557')
s = ZmqPubConnection(zf, e)
def publish():
data = [35, 11, 20, 4, 49, 1, 1, 49]
msgpack_data = msgpack.packb(data)
print "publishing %r" % data
s.publish(msgpack_data)
reactor.callLater(1, publish)
reactor.run()
对于txZMQ 0.7.0:
pivert@pivert-desktop:~/tmp/twisted$ ./example.py
publishing [35, 11, 20, 4, 49, 1, 1, 49]
Unhandled Error
Traceback (most recent call last):
File "./example.py", line 28, in <module>
reactor.run()
File "/usr/lib/python2.7/dist-packages/twisted/internet/base.py", line 1192, in run
self.mainLoop()
File "/usr/lib/python2.7/dist-packages/twisted/internet/base.py", line 1201, in mainLoop
self.runUntilCurrent()
--- <exception caught here> ---
File "/usr/lib/python2.7/dist-packages/twisted/internet/base.py", line 824, in runUntilCurrent
call.func(*call.args, **call.kw)
File "./example.py", line 24, in publish
s.publish(msgpack_data)
File "/usr/local/lib/python2.7/dist-packages/txzmq/pubsub.py", line 26, in publish
self.send(tag + b'\0' + message)
exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte 0x98 in position 0: ordinal not in range(128)
并重新执行:
pivert@pivert-desktop:~/tmp/twisted$ ./example.py
publishing [35, 11, 20, 4, 49, 1, 1, 49]
这可能就是问题所在 我通过在对publish()的调用中添加tag=b''来解决这个问题 e、 g:
pivert@pivert-desktop:~/tmp/twisted$ ./example.py
publishing [35, 11, 20, 4, 49, 1, 1, 49]
s.publish(msgpack_data, tag=b'')