2014-12-07 37 views
0

以下代码与txZMQ 0.7.0一起使用,但是在txZMQ 0.7.3上按照以下方式分解。有什么问题?这是txZMQ中的一个错误。txZMQ从0.7.0升级到0.7.3 => exceptions.UnicodeDecodeError

下面是测试代码:

#!/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:

[email protected]:~/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) 

然后,我降级txZMQ到0.7.0:

[email protected]:~# pip install txZMQ==0.7.0 

,并重新 - 执行:

[email protected]:~/tmp/twisted$ ./example.py 
publishing [35, 11, 20, 4, 49, 1, 1, 49] 

回答