title: "TypeError: a bytes-like object is required, not 'str'" during OAuth 2.0 callback request
body: <p>I'm quite new to Python 3 and Flask, and I'm currently building a simple web application to consume data from the Spotify API.</p>
  
  <p>The OAuth 2.0 authentication flow is almost working since I'm able to call <strong><a href="https://accounts.spotify.com/authorize" rel="nofollow noreferrer">https://accounts.spotify.com/authorize</a></strong> and <strong><a href="https://accounts.spotify.com/api/token" rel="nofollow noreferrer">https://accounts.spotify.com/api/token</a></strong>.</p>
  
  <p>At some point I need to request a new access and refresh token:</p>
  
  <pre><code>authentication_token = request.args['code']
  code_payload = {
      "grant_type": "authorization_code",
      "code": str(authentication_token),
      "redirect_uri": REDIRECT_URI
  }
  encoded_oauth2_tokens = base64.b64encode('{}:{}'.format(CLIENT_ID, CLIENT_SECRET))        
  headers = {"Authorization": "Basic {}".format(encoded_oauth2_tokens)}
  post_request = requests.post(SPOTIFY_TOKEN_URL, data=code_payload, headers=headers)  
  </code></pre>
  
  <p>The callback request function is failing with the following error:</p>
  
  <pre><code>File "app.py", line 52, in callback
              encoded_oauth2_tokens = base64.b64encode('{}:{}'.format(CLIENT_ID, CLIENT_SECRET))
            File "/usr/lib/python3.6/base64.py", line 58, in b64encode
              encoded = binascii.b2a_base64(s, newline=False)
          TypeError: a bytes-like object is required, not 'str' 
  </code></pre>
  
  <p>I understand that a string is being passed to <code>b64encode()</code>, but I'm not sure how can I change it to binary(?).</p>
  
  <p>During my research most similar errors were related to opening files, and this is not my scenario.       </p>