pythonlivechat

Indentation-Error is occurring and i can't seem to see what is making the error


I'm trying to make a live chat and after I'm done I get the Indentation-Error and the code down below is where the error is according to python.

    def recevied_message_from_server(self, so):
        while True:
          Buffer = so.recv(256)
          if not buffer:
              break
            message = buffer.decode('utf-8')
            if "joined" in message:
                user = message.split(": ")[1]
                message = user + " has joined"
                self.chat_area.insert('end', message + '\n')
                self.chat_area.yview(END)
            else:
                self.chat_area.insert('end', message + '\n')
                self.chat_area.yview(END)
        so.close()

Solution

  • Two things to note here:

    Check the below mentioned edited function once for reference:

    def recevied_message_from_server(self, so):
        while True:
            Buffer = so.recv(256)
            if not buffer:
                break
    
            message = buffer.decode('utf-8')
            if "joined" in message:
                user = message.split(": ")[1]
                message = user + " has joined"
                self.chat_area.insert('end', message + '\n')
                self.chat_area.yview(END)
            else:
                self.chat_area.insert('end', message + '\n')
                self.chat_area.yview(END)
    
        so.close()