vidshah97
vidshah97

Reputation: 1

How to remove the JSON Loads Error at Server Side?

I am trying to send a dictionary over Ethernet connect from my client computer to server computer. The dictionary looks like this:

data_transfer_dict={'Target':'', 'Mission':'', 'Optical/IR':'',
 'Arm':'', 'Optical Zoom':0, 'Digital Zoom':0, 'Pitch':00000,
 'Yaw':00000, 'Reset Camera':0, 'Target Selection':0, 'Take Screenshot':0}

The method I have tried is json as well as pickle JSON Code: Client Side

obj1.send_data(json.dumps(data_transfer_dict).encode('utf-8'))
def data send(self, data):
    if self.is_running:
        self.client_socket.send(data)

Server Side

while True:
    count_bytes=self.client_socket.recv(2048)
    count=json.loads(count_bytes.decode('utf-8'))
    print("Dictionary: ", count)

The above code snippet is referenced from https://www.geeksforgeeks.org/python-interconversion-between-dictionary-and-bytes/#:~:text=Method%20%3A%20Using%20encode()%20%2B%20dumps,then%20to%20corresponding%20byte%20value. The client send the data continuously in a multi thread and the server receive that data continuously. The error produced at the server side is: json.decoder.JSONDecodeError: Extra data: line 1 column 193 (char 192)

I have also referred to these page but could understand much and get help: Python json.loads shows ValueError: Extra data json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 190)

Upvotes: 0

Views: 36

Answers (0)

Related Questions