0

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!\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' (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'

  • Including your code directly in the question is preferred over linking it. How much to include is a judgment call. Large code-blocks will be given their own scroll-bar so they don't clutter the page. – ShapeOfMatter Jan 28 '21 at 17:10

2 Answers2

0

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.

ShapeOfMatter
  • 991
  • 6
  • 25
0

Your problem is this line

set.gui_done = False

set is a protected keyword in python. It's reserved for the set data type. With this line youre telling the interpreter to change the gui_done attribute of the in-built set type to false which is not allowed. That's why you're getting a TypeError. If it wasn't an in-built type you'd still get an AttributeError because set doesn't have a gui_done attribute. You probably meant to use self instead of set

BeanBagTheCat
  • 435
  • 4
  • 7