Error When Trying To Use My GitHub Token In Replit With Os.Environ

Question: I cant find out how to fix this error

Repl link/Link to where the bug appears: https://replit.com/@IzayaPantovich4/Lucky-AI

Screenshots, links, or other helpful context: GitHub - MrPrinceV2/AI-Chatbot: Lucky AI - AI CHATBOT

sh: 1: Syntax error: "(" unexpected
Traceback (most recent call last):
  File "/home/runner/EDtBFjcZpgI/main.py", line 22, in <module>
    GITHUB_TOKEN = os.environ['githubtoken']
  File "/nix/store/xf54733x4chbawkh1qvy9i1i4mlscy1c-python3-3.10.11/lib/python3.10/os.py", line 680, in __getitem__
    raise KeyError(key) from None
KeyError: 'githubtoken'
 

Are you sure that your repl has a secret with the githubtoken key? Maybe you made a typo?

3 Likes

When I run it from replit it directly on my account it works but not anyone elses for some reason

1 Like

Yes that is a safety feature. SECRETS cannot be accessed except by people with edit access to the Repl. This means that from the cover page normal users will get a keyerror. The alternative is to make the info public but that is not safe. Now, when you use SECRETS in a backend such as NodeJS or Flask, then whatever site or bot your backend creates will work with the SECRET without others getting it.

2 Likes

Bit confused, how am I supposed to hide my GitHub token like that???

TL;DR: You can’t hide your Github token AND it work for other users in a console Repl.

Replit SECRETS (os.environ): https://docs.replit.com/programming-ide/workspace-features/secrets
These simply won’t work for anybody except you and whoever you give edit access to your Repl. The only exception is if you host a bot or a website and then the bot or website backend can access them but other users cannot because that would be a major security issue. People put API keys and all sorts of other confidential stuff in SECRETS which should not be public.

2 Likes

How do I fix it? I cant seem to find a way to use my github token without it being leaked

There is no way to “fix” it. It’s a security measure.

1 Like