title: How to fix 'unpack require a buffer of 8 bytes' error when handling 8 bytes?
body: <p>I wrote a client that connects to a server written in Go. Then I send an 8 byte packet. As the response comes in, it gets passed through a function I built for unpacking it - which generates an error:</p>
  <blockquote>
  <p>Error:    line 38, in binary_response
  tag, code = struct.unpack('!I I ', response[:8])   struct.error: unpack requires a buffer of 8 bytes</p>
  </blockquote>
  <p>I've tried to take out the function and do everything in the <code>while</code> loop, but have the same error.</p>
  <pre><code>            import socket
              import struct
              import textwrap
              from time import sleep
              
              TCP_IP = '127.0.0.1'
              TCP_PORT = 4200
              
              TAB_1 = '\t - '
              TAB_2 = '\t\t - '
              TAB_3 = '\t\t\t - '
              TAB_4 = '\t\t\t\t - '
              
              DATA_TAB_1 = '\t   '
              DATA_TAB_2 = '\t\t   '
              DATA_TAB_3 = '\t\t\t   '
              DATA_TAB_4 = '\t\t\t\t   '
              
              def main():
                  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                  s.connect((&quot;127.0.0.1&quot;, 4200))
              
                  packet = struct.pack('!ii', 10, 4)
              
                  s.send(packet)
              
                  while True:
                      response = s.recv(65535)
                      bny = binary_response(response)
                      print(TAB_1 + 'Binary Response Segment:')
                      print('Response Code: ', bny[1])
                      print('Client ID: ', bny[0])
                      print('Message: ', response.decode('latin-1'))
              
              
              # Unpack binary_response
              def binary_response(response):
                  tag, code = struct.unpack('!I I ', response[:8])
                  return tag, code
              
              
              main()
              
   
  </code></pre>
  <p>What am I missing?</p>