title: TypeError: a bytes-like object is required, not 'str'
body: <p>I am trying to make a client-server model, being new to python network programming I am stuck on an error which states the following:-</p>
  
  <blockquote>
    <p>tcpCliSoc.send('[%s] %s' % (bytes(ctime(), 'utf_8'), data))   TypeError: a bytes-like object is required, not 'str'</p>
  </blockquote>
  
  <p>Here is the Server and client implementation</p>
  
  <p><strong>TCP server implementation</strong>  </p>
  
  <pre><code>from socket import *  
  from time import ctime
  
  HOST = ''  
  PORT = 21572  
  ADDR = (HOST, PORT)  
  BUFFSIZE = 1024  
  
  tcpSerSoc = socket(AF_INET, SOCK_STREAM)
  
  tcpSerSoc.bind(ADDR)
  tcpSerSoc.listen(5)
  
  while True:  
      print("waiting for connection......")  
      tcpCliSoc, addr = tcpSerSoc.accept()  
      print("connected from", addr)  
  
      while True:  
          data = tcpCliSoc.recv(BUFFSIZE)
          if not data:
              break
          tcpCliSoc.send('[%s] %s' % (bytes(ctime(), 'utf_8'), data))
      tcpCliSoc.close()
  tcpSerSoc.close()
  </code></pre>
  
  <p><strong>TCP client implementation</strong></p>
  
  <pre><code>from socket import *
  
  __author__ = 'Lamer'
  
  HOST = 'localhost'
  PORT = 21572
  ADDR = (HOST, PORT)
  BUFFSIZE = 1024
  
  tcpCliSoc = socket(AF_INET, SOCK_STREAM)
  tcpCliSoc.connect(ADDR)
  
  while True:
      data = input('&gt;')
      if not data:
          break
      tcpCliSoc.send(data.encode())
      data = tcpCliSoc.recv(BUFFSIZE)
      if not data:
          break
      print(data.decode(encoding='utf-8'))
  
  tcpCliSoc.close()
  </code></pre>