title: python socket programming TypeError: bytes like object is required not str
body: <p>I have a Python server running that listen to data that is sent by the Python client. The client takes input from the user and sends it to the server which prints it. However, I get the error that says &quot;TyperError: a byte-like object is required, not 'str'&quot;. It is on line number 8 of the client code.</p>
  <p>SERVER CODE:</p>
  <pre><code>import socket
  
  def server(interface, port):
      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
      sock.bind((interface, port))
      sock.listen(1)
      print('Listening at', sock.getsockname())
      while True:
          sc, sockname = sock.accept()
          print('We have accepted a connection from', sockname)
          print(' Socket name:', sc.getsockname())
          print(' Socket peer:', sc.getpeername())
          message = sc.recv(1024)
          print(' Incoming sixteen-octet message:', repr(message))
          sc.sendall(b'Farewell, client')
          sc.close()
          print(' Reply sent, socket closed')
  
  if __name__ == '__main__':
      server('0.0.0.0', 9999)
  </code></pre>
  <p>CLIENT CODE:</p>
  <pre><code>import socket
  
  def client(host, port):
      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      sock.connect((host, port))
      print('Client has been assigned socket name', sock.getsockname())
      command = input(&quot;message &gt; &quot;)
      sock.sendall(command)
      reply = sock.recv(1024)
      print('The server said', repr(reply))
      sock.close()
  
  if __name__ == '__main__':
      client('localhost', 9999)
  </code></pre>