Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

392
Views
Django OAuth2 unsupported_grant_type

I'm trying to send a request with django to get an access_token from my api using OAuth2. I'm executing this code :

data = {'username': 'admin', 'password': '123123', 'grant_type': 
'password','client_id': 'xxx','client_secret': 'xxx'}
headers = {'content-type': 'application/x-www-form-urlencoded'}
r = requests.post(url, data=data, headers=headers)

When I send this request I get this error :

{'error': 'unsupported_grant_type'}

Thanks for your help !

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

If anyone is interested the correct request was :

    payload = "grant_type=password&client_secret=xxx&client_id=xxx&username=username&password=password"
    headers = {
        'content-type': "application/x-www-form-urlencoded",
        'cache-control': "no-cache",
    }

    response = requests.request("POST", url, data=payload, headers=headers)
about 4 years ago · Santiago Trujillo Report

0

If you don't want to encode data in url, you can put this in your settings.

OAUTH2_PROVIDER = {                                                                                                                                                                      
    'OAUTH2_BACKEND_CLASS': 'oauth2_provider.oauth2_backends.JSONOAuthLibCore',                                                                                                          
}
about 4 years ago · Santiago Trujillo Report

0

I had the same problem and later I found that the grant type should be a string.

payload = {'grant_type': 'refresh_token', 'refresh_token': refresh_token}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!