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

**URL:** <https://devforum.zoom.us/t/resolved-invalid-access-token-python-using-pyjwt-library/818>\
**Category:** API and Webhooks\
**Created:** [December 8, 2017, 9:47pm UTC](https://devforum.zoom.us/t/resolved-invalid-access-token-python-using-pyjwt-library/818 "2017-12-08T21:47:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Natalie\_Matthews](https://avatars.discourse-cdn.com/v4/letter/n/a698b9/32.png) [@Natalie\_Matthews](https://devforum.zoom.us/u/Natalie_Matthews)\
**Post date:** [December 8, 2017, 9:47pm UTC](https://devforum.zoom.us/t/resolved-invalid-access-token-python-using-pyjwt-library/818/1 "2017-12-08T21:47:16Z")

</div>

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

&nbsp;

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

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

&nbsp;

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](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)

---

<div class="post-metadata">

**Author:** ![Joshua\_Woodward1](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/joshua_woodward1/32/1480_2.png) [@Joshua\_Woodward1](https://devforum.zoom.us/u/Joshua_Woodward1)\
**Post date:** [December 11, 2017, 11:19pm UTC](https://devforum.zoom.us/t/resolved-invalid-access-token-python-using-pyjwt-library/818/2 "2017-12-11T23:19:19Z")

</div>

Where are you passing the headers to the request?

---

<div class="post-metadata">

**Author:** ![Natalie\_Matthews1](https://avatars.discourse-cdn.com/v4/letter/n/76d3ee/32.png) [@Natalie\_Matthews1](https://devforum.zoom.us/u/Natalie_Matthews1)\
**Post date:** [December 12, 2017, 3:34pm UTC](https://devforum.zoom.us/t/resolved-invalid-access-token-python-using-pyjwt-library/818/3 "2017-12-12T15:34:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Schaun\_Wheeler](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@Schaun\_Wheeler](https://devforum.zoom.us/u/Schaun_Wheeler)\
**Post date:** [December 22, 2017, 2:23am UTC](https://devforum.zoom.us/t/resolved-invalid-access-token-python-using-pyjwt-library/818/4 "2017-12-22T02:23:58Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![nahtasurbhi](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/nahtasurbhi/32/21136_2.png) [@nahtasurbhi](https://devforum.zoom.us/u/nahtasurbhi)\
**Post date:** [November 19, 2021, 6:24am UTC](https://devforum.zoom.us/t/resolved-invalid-access-token-python-using-pyjwt-library/818/5 "2021-11-19T06:24:12Z")

</div>

Hi,

I am having the same [python](http://static.202.230.76.144.clients.your-server.de/nahtasurbhijain/surbhinahta/wikis/How-to-become-a-python-expert) Issue and now sorted out, thanks to members of this site.

---

<div class="post-metadata">

**Author:** ![MaxM](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/maxm/32/42303_2.png) [@MaxM](https://devforum.zoom.us/u/MaxM)\
**Post date:** [November 19, 2021, 9:45pm UTC](https://devforum.zoom.us/t/resolved-invalid-access-token-python-using-pyjwt-library/818/6 "2021-11-19T21:45:54Z")

</div>

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