title: TypeError: 'bytearray' object cannot be interpreted as an integer
body: <p>I want to send audio data over HTTP, but I don't understand why I'm getting this exception:</p>
  
  <blockquote>
  <pre><code>Exception happened during processing of request from ('127.0.0.1', 59976)
  Traceback (most recent call last):
    File "/usr/lib/python3.6/socketserver.py", line 654, in process_request_thread
      self.finish_request(request, client_address)
    File "/usr/lib/python3.6/socketserver.py", line 364, in finish_request
      self.RequestHandlerClass(request, client_address, self)
    File "/usr/lib/python3.6/socketserver.py", line 724, in __init__
      self.handle()
    File "/usr/lib/python3.6/http/server.py", line 418, in handle
      self.handle_one_request()
    File "/usr/lib/python3.6/http/server.py", line 406, in handle_one_request
      method()
    File "/home/vivanov/temp.py", line 113, in do_GET
      data.append(bytearray(stream.read(CHUNK)))
  TypeError: 'bytearray' object cannot be interpreted as an integer
  </code></pre>
  </blockquote>
  
  <p>The problem seems to have to do with passing values to <code>wfile.write</code>.</p>
  
  <p>How can I resolve the issue?</p>
  
  <p>This is the code I have:</p>
  
  <pre class="lang-py prettyprint-override"><code>class ChunkingRequestHandler(BaseHTTPRequestHandler):
      ALWAYS_SEND_SOME = False
      ALLOW_GZIP = False
      protocol_version = 'HTTP/1.1'
      def do_GET(self):
          ae = self.headers.get('accept-encoding') or ''
  
          # send some headers
          self.send_response(200)
          self.send_header('Transfer-Encoding', 'chunked')
          self.send_header('Content-type', 'audio/x-wav')
  
          self.end_headers()
  
          data = bytearray(wav_header)
          data.append(bytearray(stream.read(CHUNK)))
          print(data)
          self.wfile.write(b"%X\r\n%s\r\n" % (len(data), data))
  
          while True:
              data = bytearray(stream.read(CHUNK))
              self.wfile.write(b"%X\r\n%s\r\n" % (len(data), data))
  
          # send the chunked trailer
          self.wfile.write('0\r\n\r\n')
  </code></pre>