python' TypeError:参数必须是字符串或只读字符缓冲区,而不是元组'

时间:2016-03-02 19:47:43

标签: python string

我使用python 2.7编写了这段代码:

list[5] = {1,1,2,2,3};
liste[5] = {0,0,1,1,2};

但是我收到了这个错误:

  

TypeError:参数必须是字符串或只读字符缓冲区,而不是元组

该行引出此错误:class LoadBalancerHandler: def __init__(self, file_name): self.server_socket = socket.socket(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) file = open(file_name) setup_apps(file.read()) def listen(self, host='localhost', port=80): self.server_socket.bind((host,port)) self.server_socket.listen(5) while True: (client_socket, address) = self.server_socket.accept() threadHandling = ThreadHandling(client_socket, self) threadHandling.start()

1 个答案:

答案 0 :(得分:1)

同样,我认为你对socket.socket(...)的选择是不正确的。如果您正在尝试创建TCP侦听器,则可以使用

import socket
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(('localhost',5555))
s.listen(5)