title: Spotify API {'error': 'invalid_client'} Authorization Code Flow [400]
body: <p>This is one of my many attempts at making a POST request to <a href="https://accounts.spotify.com/api/token" rel="noreferrer">https://accounts.spotify.com/api/token</a>. </p>
  
  <p>Scope was set to 'playlist-modify-public, playlist-modify-private'.</p>
  
  <p>I'm using Python 3.7, Django 2.1.3.</p>
  
  <p>No matter what I do, response_data returns {'error': 'invalid_client'}</p>
  
  <p>I've tried many things, including passing the client_id/client_secret inside the body of the request as per the <a href="https://developer.spotify.com/documentation/general/guides/authorization-guide/" rel="noreferrer">official Spotify documentation</a> for this particular request... to no avail. </p>
  
  <p>Please help!</p>
  
  <pre><code>def callback(request):
  
      auth_token = request.GET.get('code')     # from the URL after user has clicked accept
      code_payload = {
          'grant_type': 'authorization_code',
          'code': str(auth_token),
          'redirect_uri': REDIRECT_URI,
      }
  
      auth_str = '{}:{}'.format(CLIENT_ID, CLIENT_SECRET)
      b64_auth_str = base64.b64encode(auth_str.encode()).decode()
  
      headers = {
          'Content-Type': 'application/x-www-form-urlencoded',
          'Authorization': 'Basic {}'.format(b64_auth_str)
      }
  
      post_request = requests.post(SPOTIFY_TOKEN_URL, data=code_payload, headers=headers)
  
      response_data = json.loads(post_request.text)
          # ==&gt; {'error': 'invalid_client'}
  </code></pre>