os.environ.get("REPL_OWNER") without an account

My Code:

from os import environ

username = os.environ.get("REPL_OWNER")

if username is None:
  username = "Guest"
else:
  #rest of code is irrelevant

I tested this without a replit acount, assuming it to return None (and when it does, I assign the string “Guest” to username).
However, when I ran it, it always ran the else statement instead. It turns out, for some reason, it returned the string “five-nine” instead of NoneType.

Also, what confuses me even more is when I tried to search for username in a list, it returned the error: TypeError: NoneType object is not subscriptable.

I have fixed my code now but I have a few questions.
(My New Code):

if username == "five-nine":
  username = "Guest"
  1. Why does it return “five-nine”?
  2. Does it return “five-nine” for everyone/ will my new code work for everyone?
  3. Why did it produce that TypeError if username = “five-nine” and not None?
1 Like

Note: I meant to put environ.get(“REPL_OWNER”) in the first bit of code, not os.environ.get("REPL_OWNER)

Hi @IsaacBell4 , welcome to the forums!
At the username line, try environ['REPL_OWNER'] instead, as that’s how I use environ.

You can edit your post by pressing the pencil icon at the bottom of your post.

Hi @IsaacBell4 !
Has my post above worked? Please tell me if it doesn’t, so that I can help you further.
Thanks!

For some reason I can’t find the pencil icon.

I have tried that and it still returns “five-nine” instead of NoneType

I think Replit assigns a default value to certain environment variables for operational purposes. “five-nine” might be such a placeholder value used by Replit.

It really depends on the first scenario, if “five-nine” is indeed a standard placeholder for guest users, I think your code should work fine.

Maybe somewhere in your code you are trying to perform an operation on username that is only valid for list-like?

The thing is, relying on hardcoded can give you headches. Checking for a range of conditions that define what an acceptable or expected value is, is more reliable.

Maybe not?

2 Likes

Something like this:

username = getenv("REPL_OWNER")

# You can check if username is None, empty, or a known placeholderm it's more reliable
if username is None or username == "" or username == "five-nine":
    username = "Guest"
2 Likes

five-nine is the name of the account used for running and ghost-forking repls when logged out. It’s a banned account @five-nine

1 Like

Sorry for the late reply, but thanks for the answers!

For the rest of the code, the line that was producing the error was just saying: if username not in db["Users"]: and then it would produce the TypeError.

Oh thanks, so I’m assuming it should work for everyone then, right?

8 posts were split to a new topic: About five-nine

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.