Unable to access GITHUB_TOKEN

I’m trying to use the GITHUB_TOKEN to authenticate on behalf of GitHub Actions. I’m trying to access the “GITHUB_TOKEN” environment variable through a Python file, which is run when the action is triggered. But for some reason, it seems like the environment variable doesn’t exist.

My Python file is using the PyGithub package to authenticate:

import os
from github import Github

github = Github(os.environ["GITHUB_TOKEN"])

and it throws this error:

Traceback (most recent call last):
  File "add_url.py", line 4, in <module>
    github = Github(os.environ["GITHUB_TOKEN"])
  File "/usr/lib/python2.7/UserDict.py", line 40, in __getitem__
    raise KeyError(key)
KeyError: 'GITHUB_TOKEN'
##[error]Process completed with exit code 1

Am I misinterpreting the docs? Here’s the full error log

You need to set the env variable explicitly:

env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

1 Like