title: PYTHON: requests.post() how to send request_body encoded as application/x-www-form-urlencoded
body: <p>I'm doign an app with the Spotify API. My problem is I'm trying to get an <code>access_token</code> but It's not working. In the docs it says i need to send the body encoded as application/x-www-form-urlencoded so I search a little bit and It should work just setting <code>request_body</code> as a dictionary.</p>
  <p>This is the code of my function:</p>
  <pre><code>    def get_access_token(self):
          auth_code, code_verifier = self.get_auth_code()
          endpoint = &quot;https://accounts.spotify.com/api/token&quot;
  
          # as docs said data should be encoded as application/x-www-form-urlencoded
          # as internet says i just need to send it as a dictionary. However it's not working
          request_body = {
                  &quot;client_id&quot;: f&quot;{self.client_ID}&quot;,
                  &quot;grant_type&quot;: &quot;authorization_code&quot;,
                  &quot;code&quot;: f&quot;{auth_code}&quot;,
                  &quot;redirect_uri&quot;: f&quot;{self.redirect_uri}&quot;,
                  &quot;code_verifier&quot;: f&quot;{code_verifier}&quot;
          }
  
          response = requests.post(endpoint, data=request_body)
          print(response)
  </code></pre>
  <p>The response I'm getting is always <code>&lt;Response [400]&gt;</code>
  Here are the docs, step 4 <a href="https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow-with-proof-key-for-code-exchange-pkce" rel="noreferrer">https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow-with-proof-key-for-code-exchange-pkce</a>
  NOTE: I tryed executing this as a curl and it works fine I'm not sure what I'm doing wrong in the python code
  here's the command:</p>
  <pre><code>curl -d client_id={self.client_ID} -d grant_type=authorization_code -d code={auth_code} -d redirect_uri={self.redirect_uri} -d code_verifier={code_verifier} https://accounts.spotify.com/api/token
  </code></pre>