2017-04-04 12 views
0

私はOAuth2を使用して私のAPIからaccess_tokenを取得するためにdjangoでリクエストを送信しようとしています。Django OAuth2 unsupported_grant_type

{ 'エラー': 'unsupported_grant_type'}あなたの助けを

おかげで、私はこのエラーを取得し、この要求を送信すると

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) 

:私はこのコードを実行しています!

答えて

2

誰もが興味を持っている場合は、正しい要求されました:この回答のため

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) 
+0

感謝。私はcontent-typeとしてapplication/jsonを使っていました。 x-www-form-urlencodedに切り替えることは、client_credentials認可タイプで動作するように変更するだけでした。 –

関連する問題