(resolved) "Invalid access token." - Python using PyJWT library

RESOLVED

To help someone else…

jwt.encode(…) returns a token in bytes, this must be decoded using token.decode() to use in your get request

 

Using this library (listed on jwt.io) https://pyjwt.readthedocs.io/en/latest/

I am getting  {“code”:124,“message”:“Invalid access token.”}

 

This is my script:

import time
import datetime
import requests
import jwt

KEY =
SECRET =

header = {
“alg”: “HS256”,
“typ”: “JWT”
}

payload = {
“iss”: KEY,
“exp”: int(time.time() + 60)
}

token = jwt.encode(payload, SECRET, algorithm=‘HS256’, headers=header)

today = datetime.date.today()
yesterday = today - datetime.timedelta(1)

base_url = “https://api.zoom.us/v2/metrics/meetings

r = requests.get(’%s/?type=%s&from=%s&to=%s’ % (base_url, “past”, yesterday, today),
headers={‘Authorization’: ‘Bearer %s’ % token})

print(r.content)

Where are you passing the headers to the request?

This is all one line:

r = requests.get(’%s/?type=%s&from=%s&to=%s’ % (base_url, “past”, yesterday, today),
headers={‘Authorization’: ‘Bearer %s’ % token})

It’s okay though, I got it working.

Natalie, can you share what you did to get it working?

Wait, nevermind, just saw you edit at the top of your original post :slight_smile:

Hi,

I am having the same python Issue and now sorted out, thanks to members of this site.

1 Like

That’s great to hear @nahtasurbhi! We are always happy to hear that this community is valuable. Thanks for being part of it.