0
我有以下python套接字客戶端。其中發送一個小消息到套接字服務器。在Python2.7中,這個工作沒有缺陷。然而在3.4中,我得到以下回溯。實施改變了嗎?我應該採取什麼方法進行調試?Python2.7 vs Python3.4 socket.send
Traceback (most recent call last):
File "echo-client.py", line 19, in <module>
sockobj.send(line)
TypeError: 'str' does not support the buffer interface
import sys
from socket import *
_server = 'localhost'
_port = 50007
message = ['Hello network world']
if len(sys.argv) > 1:
_server = sys.argv[1]
if len(sys.argv) > 2:
_port = sys.argv[2]
sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.connect((_server, _port))
for line in message:
sockobj.send(line)
data = sockobj.recv(1024)
print('Client received: {}'.format(data))
sockobj.close()