title: The code below sends a string and list through a client server network
body: <p>My code isn't sending the list below to the server side. How do I  serialize list into bytes to be sent over a Clint server network? </p>
  
  <p>Error message: info=pickle.loads(buf)
  _pickle.UnpicklingError: invalid load key,'H'.     </p>
  
  <pre><code>import socket
  import sys
  from io import BytesIO 
  import struct
  import pickle
  portnum = 5000
  hostname = 'localhost'
  
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  server_addr = (hostname,portnum)
  sock.connect(server_addr)
  msg = "Hello There!"
  numbers = [1,2,3,4,5]
  
  sock.send(str.encode(msg)) 
  serial_grades = pickle.dumps(numbers)
  sock.send(serial_grades)
  
  print("Message sent")
  sock.close()
  print ("Sending message: ", msg)
  print ("done.")
  sock.close()
  
  import struct
  import socket
  import sys
  from io import BytesIO 
  import pickle
  
  port = 5000
  hostname = 'localhost'
  
  def byte_to_string(bytes_):
      bytes_ = str(bytes_)
      return bytes_[2:len(bytes_) - 1] 
  
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  sock.bind((hostname, port))
  sock.listen(2)
  print ("Ready. Listening to socket...")
  
  conn,addr = sock.accept()
  buf = conn.recv(8092)
  buf_2 = conn.recv(8092)
  
  response = byte_to_string(buf)
  info=pickle.loads(buf)
  
  print(info)
  print ("We've got a message "+str(response))
  sock.close()
  </code></pre>