0

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:

Current Issue is: enter image description here

Any suggestions?

Tom
  • 16,842
  • 17
  • 45
  • 54
Oksana Ok
  • 515
  • 3
  • 7
  • 19
  • @forkdbloke your edit is discussed on meta: https://meta.stackoverflow.com/questions/392084/are-edits-just-to-replace-urls-with-links-okay/392091#392091 – Kami Kaze Dec 11 '19 at 15:51
  • @KamiKaze while i was editing all the posts, i had made sure that "i retain the thought process of the owner of the post" i.e without editing the whole sentences, however, since, the owner was not careful to make the links inline, i took only such posts and making the links in-line. Unfortunately, stackoverflow does not get back on why few reviews were "rejected". Otherwise, i would have improved the posts long time ago itself. – forkdbloke Dec 11 '19 at 16:09
  • @forkdbloke You might want to go with this to the meta thread. I understand where you are coming from. The problem is that sometimes (as discussed on meta) it gets rather sub-optimal results. In your profile you can look up all your edits and when looking at them in detail you can see reject reasons (also for approved ones where someone suggested a rejection), but most of the time it is a pre written text that does not go into detail. Anyhow thank you for participating. – Kami Kaze Dec 11 '19 at 16:18
  • @KamiKaze thank you i have put forth my thought on meta as well. going forward, i shall be careful. I apologize if that has caused some inconvenience to you and others. I shall improve going forward. – forkdbloke Dec 11 '19 at 16:20

1 Answers1

1

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.

denniseagles
  • 57
  • 1
  • 8