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


#1

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)


#2

Where are you passing the headers to the request?


#3

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.


#4

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: