tonysimpson / nanomsg-python

nanomsg wrapper for python with multiple backends (CPython and ctypes) should support 2/3 and Pypy
MIT License
382 stars 85 forks source link

TypeError on Python 3.4.3 #51

Closed hotpxl closed 8 years ago

hotpxl commented 8 years ago

bind throws TypeError on Python 3.4.3 if I pass in a string. It works if I pass in a bytes instead. I think both should work by automatically converting between them inside of bind. It's not intuitive for the user to do the encoding.

Python 3.4.3+ (default, Oct 10 2015, 09:15:38) 
Type "copyright", "credits" or "license" for more information.

IPython 4.1.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import nanomsg
/home/lyt/.virtualenvs/e3/lib/python3.4/site-packages/nanomsg_wrappers/__init__.py:22: UserWarning: Could not load the default wrapper for your platform: cpy, performance may be affected!
  "%s, performance may be affected!") % (default,))

In [2]: s1 = nanomsg.Socket(nanomsg.PAIR)

In [3]: s1.bind('inproc://a')
---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)
<ipython-input-3-ec2f3e46907a> in <module>()
----> 1 s1.bind('inproc://a')

/home/lyt/.virtualenvs/e3/lib/python3.4/site-packages/nanomsg/__init__.py in bind(self, address)
    271             raise ValueError("Nanoconfig address must be sole endpoint")
    272         endpoint_id = _nn_check_positive_rtn(
--> 273             wrapper.nn_bind(self._fd, address)
    274         )
    275         ep = Socket.BindEndpoint(self, endpoint_id, address)

ArgumentError: argument 2: <class 'TypeError'>: wrong type

In [4]: s1.bind(b'inproc://a')
Out[4]: <BindEndpoint socket <Socket fd 0, connected to [b'inproc://a'], bound to []>, id 1, addresss b'inproc://a'>