[issue4275] socketserver example code not correctly ported to py3k

Brad Miller report at bugs.python.org
Fri Nov 7 21:03:30 CET 2008


Brad Miller <bonelake at gmail.com> added the comment:

I found a similar problem in the Demo/sockets/unixclient.py code.

from socket import *

FILE = 'unix-socket'
s = socket(AF_UNIX, SOCK_STREAM)
s.connect(FILE)
s.send('Hello, world')
data = s.recv(1024)
s.close()
print('Received', repr(data))

Produces the following error message:

Traceback (most recent call last):
  File "unixclient.py", line 9, in <module>
    s.send('Hello, world')
TypeError: send() argument 1 must be string or buffer, not str

My question is around whether the examples are wrong and 'Hello, World'
should simply be wrapped with bytearray('Hello, World','utf8')   or
whether the underlying socket implementation is wrong.  Judging by the
error message above it looks like the implementation is catching just
this kind of error and the example should be changed.  But, this must
break backward compatibility all over the place.  And since the bug has
release blocker it makes me think the socket implementation should be
changed.

----------
nosy: +bmiller

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4275>
_______________________________________


More information about the Python-bugs-list mailing list