Code does not work, error
File "chat.py", line 43, in sendproc sock.sendto (name.get()+':'+text.get(),('localhost',11719)) TypeError: a bytes-like object is required, not 'str' here is the code
# -*- coding: utf-8 -*- import socket from tkinter import * tk=Tk() s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) s.bind(('localhost',11719)) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1) text=StringVar() name=StringVar() name.set('HabrUser') text.set('') tk.title('MegaChat') tk.geometry('400x300') log = Text(tk) nick = Entry(tk, textvariable=name) msg = Entry(tk, textvariable=text) msg.pack(side='bottom', fill='x', expand='true') nick.pack(side='bottom', fill='x', expand='true') log.pack(side='top', fill='both',expand='true') def loopproc(): log.see(END) s.setblocking(False) try: message = s.recv(128).decode() log.insert(END,message+'\n') except: tk.after(1,loopproc) return tk.after(1,loopproc) return def sendproc(event): sock.sendto (name.get()+':'+text.get(),('localhost',11719)) text.set('') msg.bind('<Return>',sendproc) msg.focus_set() tk.after(1,loopproc) tk.mainloop()