title: How to send the content of a dictionary properly over sockets in python3x?
body: <p>Using sockets in <code>python3.x</code> I want to send the content of a dictionary over a socket, which for some reasons is NOT answered by the link just above this line...</p>
  
  <p>client.py:</p>
  
  <pre><code>a = {'test':1, 'dict':{1:2, 3:4}, 'list': [42, 16]}
  bytes = foo(a)
  sock.sendall(bytes)
  </code></pre>
  
  <p>server.py: </p>
  
  <pre><code>bytes = sock.recv()
  a = bar(bytes)
  print(a)
  </code></pre>
  
  <p>How to convert any dictionary to a sequence of bytes (to be able to be sent through a socket) and how to be converted back? I prefer a clean and simple way to do this.</p>
  
  <p>What I have tried so far: </p>
  
  <pre><code>sock.sendall(json.dumps(data))
  TypeError: 'str' does not support the buffer interface
  
  sock.sendall(bytes(data, 'UTF-8'))
  TypeError: encoding or errors without a string argument
  
  data = sock.recv(100)
  a= data.decode('UTF-8')
  AttributeError: 'str' object has no attribute 'decode'
  </code></pre>