![](/img/trans.png)
[英]how can I fix TypeError: can't set attributes of built-in/extension type 'cimpl.Consumer'
[英]How to fix - TypeError: can't set attributes of built-in/extension type 'set'
我對 python 比較陌生,我正在嘗試與 python 進行簡單的 GUI 聊天。 它被編程為在客戶端加入服務器時詢問昵稱。 一切正常,直到我輸入昵稱的部分。 當我輸入昵稱時,我分別從服務器和客戶端收到這些錯誤,我也會提供回溯。
ConnectionResetError: [Errno 104] Connection reset by peer
(來自服務器)
追溯:
Traceback (most recent call last):
File "server.py", line 51, in <module>
receive()
File "server.py", line 44, in receive
broadcast(f"{nickname} entered to the chat!\n".encode('utf-8'))
File "server.py", line 17, in broadcast
client.send(message)
TypeError: can't set attributes of built-in/extension type 'set'
(來自客戶端)
追溯:
Traceback (most recent call last):
File "C:/Users/ISINDU WICKRAMASEKAR/PycharmProjects/guichat/client.py", line 94, in <module>
client = Client(HOST, PORT)
File "C:/Users/ISINDU WICKRAMASEKAR/PycharmProjects/guichat/client.py", line 22, in __init__
set.gui_done = False
服務器和客戶端的代碼也是鏈接的。
服務器-> https://pastebin.com/0W7Cw9Cu
客戶端-> https://pastebin.com/FES2UNc1
我試過的:
我嘗試在谷歌上搜索答案,但我不能說我沒有得到任何答案,但我不明白如何為我的問題實施這些解決方案。 這些是我提到的鏈接
我認為錯誤消息非常准確地指出了問題所在。
Traceback (most recent call last):
File "C:/Users/ISINDU WICKRAMASEKAR/PycharmProjects/guichat/client.py", line 94, in <module>
client = Client(HOST, PORT)
File "C:/Users/ISINDU WICKRAMASEKAR/PycharmProjects/guichat/client.py", line 22, in __init__
set.gui_done = False
TypeError: can't set attributes of built-in/extension type 'set' (from client)
在 client.py 的第 22 行,您嘗試分配set.gui_done = False
; 您可能的意思是self.gui_done
。
你的問題是這條線
set.gui_done = False
set
是 python 中的受保護關鍵字。 它是為set
數據類型保留的。 通過這一行,您告訴解釋器將內置set
類型的gui_done
屬性更改為 false,這是不允許的。 這就是你得到TypeError
的原因。 如果它不是內置類型,您仍然會收到AttributeError
,因為set
沒有gui_done
屬性。 您可能打算使用self
而不是set
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.