TypeError: send() argument 1 must be string or read-only buffer, not int
Fredrik Lundh
fredrik at pythonware.com
Thu Feb 17 15:26:40 EST 2005
Manish Gupta wrote:
> invoking something like following -
>
> sock.send(100)
>
> generates the following error -
>
> TypeError: send() argument 1 must be string or read-only buffer, not int
>
> > how can I work around this? I wish to write
> msg-length on a stream socket.
in what form?
sock.send(chr(100)) # single byte
sock.send(str(100)+"\n") # ascii characters plus newline
sock.send(str(100)+":") # netstring prefix
sock.send("%08d" % 100) # eight ascii characters, null-padded
sock.send(str(100).encode("utf-16")) # same, in utf-16 with bom
sock.send(struct.pack("!i", 100)) # 32-bit integer in network byte order
etc. (see the struct module documentation for more alternatives)
</F>
More information about the Python-list
mailing list