title: Using the auth0 /oauth/token endpoint from python
body: <p>I'm trying to figure out how Auth0 works. So far I'm not lucky. What I am trying to achieve is simple: POST to the oauth/token endpoint and receive a token in return. With curl this is no problem. I can curl --request POST [...] and receive a token just fine. When I try to do this using python and pythons requests module I'm getting an error stating that I'm not authorized. The data is exactly the same, I double checked. Here's my python code:</p>
  
  <pre><code>import json, requests
  
  endpoint = 'https://mydomain.auth0.com/oauth/token'
  data = {
      'grant_type': 'password',
      'username': 'myuser',
      'password': 'mypassword',
      'audience': '',
      'scope': 'read:sample',
      'client_id': 'myclientid',
      'client_secret': 'myclientsecret'
  },
  headers = {'content-type': 'application/json'}
  
  response = requests.post(url=endpoint, data=json.dumps(data), headers=headers)
  print("STATUS: ", response.status_code)
  print("Response: ", response.json())
  </code></pre>
  
  <p>Working Curl request:</p>
  
  <pre><code>curl --request POST \\
    --url 'https://mydomain.auth0.com/oauth/token' \\
    --header 'content-type: application/json' \\
    --data '{"grant_type":"password","username": "myuser","password": "mypassword","audience": "", "scope": "read:sample", "client_id": "myclientid", "client_secret": "myclientsecret"}'
  </code></pre>
  
  <p>I also tried setting the user agent in my python code to "curl/7.51.0", but that also did not work :D</p>
  
  <p>I'm happy with any pointer!</p>
  
  <p>EDIT:</p>
  
  <p>I shamefully have to admit that I did not use the same username afterall. That didn't change the fact though that I could not authorize myself with the python code. The SDK as suggested by @cricket_007 works fine. I find this a little bit weird but well.</p>