Oauth flow in github api v3 not working
So, this should be pretty simple, but I can't seem to find my point of failure. Hopefully someone else can point me out.
First I go to https://github.com/login/oauth/authorize?client_id=CLIENT_ID&scope=gist
and this gives me back the code. Then I do this:
import requests, json
client_id = XXXX
client_secret = XXXX
code = XXXX
r = requests.post(
'https://github.com/login/oauth/access_token',
data=json.dumps({
'client_id':client_id,
'client_secret':client_secret,
'code':code
})
r.content # this gives me a 404 header
When I go to my test user, it shows me as authorized and my application shows it has one user, but I don't have an access token.
What am I doing wrong.
+3
source to share
1 answer
Well, I was right, it was a very simple problem, but I will leave it here in case others encounter the same error.
When in doubt, manually define your title. Therefore, you need:
header = {'content-type':'application/json'}
And then pass in the header:
r = requests.post(
'https://github.com/login/oauth/access_token',
data=json.dumps({
'client_id':client_id,
'client_secret':client_secret,
'code':code
}),
headers=header
)
It solved the problem for me.
+12
source to share