1
試圖運行在命令提示符下Python代碼: 我使用Python 2ZMQ套接字類型錯誤:僅Unicode字符串錯誤:是否有修復?
import zmq
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect('tcp://0.0.0.0.:6667')
socket.setsockopt_string(zmq.SUBSCRIBE, 'value')
並得到以下錯誤,當我執行:
socket.setsockopt_string(zmq.SUBSCRIBE, value) File "C:\Program Files\Anaconda2\lib\site-packages\zmq\sugar\socket.py", line 192, in >set_string raise TypeError("unicode strings only") TypeError: unicode strings only
你能請告知在方案?
那麼,你有沒有試過將[Unicode字符串](https://docs.python.org/2/howto/unicode.html#unicode-literals-in-python-source-code)傳遞給'setsockopt_string()'? –
也許這可以幫助:http://stackoverflow.com/questions/4182603/python-how-to-convert-a-string-to-utf-8 – PerunSS
我已經嘗試所有建議的方法在https://docs.python .org等/ 2/HOWTO/unicode.html#Unicode的文字合蟒源代碼 – stats999