title: http.client.BadStatusLine: '' when attempting app-only twitter oauth with python3
body: <p>I am trying to create a script that will process <code>Twitter</code> streams.  Unfortunately, the OAuth process has stymied me.  Adopting some code I found on the internet, I receive a blank response from <a href="https://api.twitter.com/oauth/token" rel="nofollow">https://api.twitter.com/oauth/token</a>.  In order to better understand the process, I am trying to do this without special modules.  Here is my code, what am missing?  Any help would be greatly appreciated.</p>
  
  <p>Code:</p>
  
  <pre><code>import http.client
  import urllib
  import base64
  
  CONSUMER_KEY = 'yadayadayada'
  CONSUMER_SECRET = 'I am really tired today'
  
  encoded_CONSUMER_KEY = urllib.parse.quote(CONSUMER_KEY)
  encoded_CONSUMER_SECRET = urllib.parse.quote(CONSUMER_SECRET)
  concat_consumer_url = encoded_CONSUMER_KEY + ':' + encoded_CONSUMER_SECRET
  
  
  host = 'api.twitter.com'
  url = '/oauth2/token/'
  params = urllib.parse.urlencode({'grant_type' : 'client_credentials'})
  req = http.client.HTTPSConnection(host, timeout = 100)
  req.set_debuglevel(1)
  req.putrequest("POST", url)
  req.putheader("Host", host)
  req.putheader("User-Agent", "My Twitter 1.1")
  req.putheader("Authorization", "Basic %s" % base64.b64encode(b'concat_consumer_url'))
  req.putheader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
  req.putheader("Content-Length", "29")
  req.putheader("Accept-Encoding", "identity")
  req.endheaders()
  
  req.send(b'params')
  
  resp = req.getresponse()
  
  
  print ("{} {}".format(resp.status, resp.reason))
  </code></pre>
  
  <p>Error message:</p>
  
  <pre><code>C:\Python33&gt;app_only_test_klug.py
  Traceback &lt;most recent call last&gt;:
      File "C:\Python33\app_only_test_klug.py", line 31, in &lt;module&gt;
          resp = req.getresponse()
      File "C:\Python33\lib\http\client.py", line 1131, in getresponse
          response.being()
      File "C:\Python33\lib\http\client.py", line 354, in begin
          version, status, reason = self._read_status()
      File "C:\Python33\lib\http\client.py", line 324, in _read_status
          raise BadStatusLine(line)
  http.client.BadStatusLine: ''
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>UPDATE:</p>
  
  <p>After some more tinkering, I believe that the issue lies with my base64 encoding:</p>
  
  <p>req.putheader("Authorization", "Basic %s" % base64.b64encode(b'concat_consumer_url'))</p>
  
  <p>When I decode the resulting encoding of the above, I get "b'concat_consumer_url'" rather than a concatenation of the encoded_CONSUMER_KEY and encoded_CONSUMER_SECRET combined around a colon.  How do I get the base64 to b64encode the value that concat_comsumer_url represents rather than the string "concat_consumer_url" so that I can move forward?  Thanks in advance.</p>