选择Module:使用套接字服务器遇到TypeError。 [蟒蛇]

时间:2013-05-19 18:49:16

标签: python select module typeerror

问题在于我的套接字服务器中的select.select行。

r_list, w_list, x_list = select.select(U_Connections + [ss], Username_List, [])

其中:

Username_List = []
U_Connections = []

问题在于Username_List

Username_List只应该做一件事,那就是服务器收到的商店用户名。每当服务器收到数据时,它都会检查Username_List中是否有该用户名(收到的数据)。

如果它在那里,它只是继续,并忽略收到的数据。

如果不是,则将数据添加到列表中,然后向所有连接的客户端发送新用户名。这是程序崩溃的地方。

if data:
    translated_data = data.decode()
    print(translated_data)
    print("2")
    if translated_data in Username_List:
        pass
    else:
        translated_data_string = str(translated_data)
        Username_List.append(translated_data_string)    <--- HERE
        print("3")

此阶段完成后,while循环将重新执行。并且在此过程中遇到TypeError。只要向w_list添加任何内容,就会发生这种情况。

我做错了什么,我应该如何使用select模块来完成这项工作?

我需要做的就是将用户名附加到列表中,然后如果收到的用户名不在现有列表中,则将其发送给每个人。

我一直试图解决这个问题一段时间,并且做了一些环顾四周,但似乎找不到修复。

我读到了这个:

  

“换句话说:每个参数必须是一个平坦的序列,没有嵌套   允许“。

this帖子中。但我真的不明白做错了什么。

服务器的完整代码位于pastebin here (注意我有except:抓住TypeError

如果有人能够解释我如何正确解释选择模块,我将非常感激。我不想问愚蠢的问题。

遇到错误:

Traceback (most recent call last):
  File "C:\Users\Owatch\Documents\Unisung\Produced Content\NetSendClient[0.7]\NetSendClient[0.7]\NetSendClient\files\Program_Files\Username_Server.py", line 23, in <module>
    r_list, w_list, x_list = select.select(U_Connections + [ss], Username_List, [])
TypeError: argument must be an int, or have a fileno() method.

0 个答案:

没有答案