Using sockets in python3.x
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...
client.py:
a = {'test':1, 'dict':{1:2, 3:4}, 'list': [42, 16]}
bytes = foo(a)
sock.sendall(bytes)
server.py:
bytes = sock.recv()
a = bar(bytes)
print(a)
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.
What I have tried so far:
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'