Reputation: 555
I would like to pull reporting data from Xero by using Python.
This is what I have managed to do currently:
def keyGen():
url_key = 'https://identity.xero.com/connect/token'
key = '{}'.format(CLIENT_ID + ":" + CLIENT_SECRET)
key2 = str(base64.b64encode(key.encode())).replace("b'",'').replace("'",'')
headers_key = {
'Authorization': 'Basic {}'.format(key2),
'Content-type': 'application/x-www-form-urlencoded',
}
data = [
('grant_type', 'authorization_code'),
#('code', 'xxxx'),
#('redirect_uri', 'http://localhost:5000/callback')
]
response = requests.post(url_key, headers=headers_key,data=data)
jsonResponseKey = response.json()
I'm not good with OAuth2.0 especially with App / Redirect URL and etc., I do not have full vision.
Extra information:
Any suggestions?
Upvotes: 0
Views: 850
Reputation: 57
I would recommend that you look at the pyxero library - it is a great python wrapper to deal with OAuth and xero API access.
I initially spent hours trying to get Authlib working, and while it does a lot more than pyxero, including server side OAuth issuing, for what I needed I could get pyxero up & running in a fraction of the time.
OAuth2 steps and sample code is set out on the pyxero github repo.
Upvotes: 1