0

How to send dictionary datatype object over a socket? I know from Python 3, we have to use encode() and decode() while sending and receving a string through a socket, like socket.send(data.encode()) and socket.recv(data.decode()). How are we supposed the same thing for dictionary?

Apoorva Somani
  • 515
  • 1
  • 6
  • 23

1 Answers1

0

I think you can use:

serialized_dictionary = json.dumps(your_dictionary) 
your_dictionary=json.loads(serialized_dictionary)

Don't forget to import json module:

import json

Hope this helps! =)

More on json module here

jlnabais
  • 829
  • 1
  • 6
  • 18
  • Found a similar question (check this too): http://stackoverflow.com/questions/15190362/sending-a-dictionary-using-sockets-in-python – jlnabais Sep 11 '15 at 20:49