Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

python - How to fix - TypeError: can't set attributes of built-in/extension type 'set'

I'm relatively new to python and I'm trying to make a simple GUI chat with python. It is programmed to ask for a nickname when a client joins the server. All works fine until the part where I enter the nickname. When I enter the nickname I get these errors from the server and client respectively, I'll provide the tracebacks as well.

ConnectionResetError: [Errno 104] Connection reset by peer (From server)

traceback:

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!
".encode('utf-8'))
  File "server.py", line 17, in broadcast
    client.send(message)

TypeError: can't set attributes of built-in/extension type 'set' (from client)

traceback:

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

The code for the server and client are also linked.

server -> https://pastebin.com/0W7Cw9Cu

client-> https://pastebin.com/FES2UNc1

What I have tried:

I tried googling for answers and I can't say I didn't get any, but I didn't understand how to implement those solutions for my issue. These are the links I referred to

  1. Python handling socket.error: [Errno 104] Connection reset by peer

  2. python can't set attributes of built-in/extension type 'object'

question from:https://stackoverflow.com/questions/65941875/how-to-fix-typeerror-cant-set-attributes-of-built-in-extension-type-set

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think the error message points us to the problem pretty precisely.

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)

On line 22 of client.py, you try to assign set.gui_done = False; you probably meant self.gui_done.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...