2
votes

pls correction with correct syntax pythoh piece of Code that cause error:

def reliable_send(self, data):
        json_data = json.dumps(data)
        self.connection.send(json_data)

Error is:

self.connection.send(json_data) at json_data whic is

TypeError: a bytes-like object is required, not 'str'

1

1 Answers

1
votes

you need to encode the data before sending, this should be the solution

def reliable_send(self, data):
    json_data = json.dumps(data)
    self.connection.send(json_data.encode())