#๐ KeyError
58 messages ยท Page 1 of 1 (latest)
@mortal cove
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
are you sure the env file exist and properly save with the correct data?
Yeah it definitely exists and has a value for CLIENT_ID
have you try print env
it might be a cwd issue. so it might not look for the file in the correct location
good idea, I just have done and the output is completely different to what is in my env file haha
ah okay so how do I fix this?
the environment contains not only your own variables. it's normal to have lots of other stuff
depends on how you run it
what do you mean?
cwd depends on the folder you run it from, but what that is ultimately depends on the way you run your python file... from terminal? from IDE? some other way?
ah, I'm running it from terminal
the directory you're inside of, is typically your cwd (current working directory)
and I'm somewhat sure python-dotenv looks in that folder for your .env file
my python file and env file are in the same directory
yea, but the directory where your python file is, is not necessarily your current working directory
can you show the terminal and the comand you use to run your python script?
(admin cmd prompt)
and the .env file is also in the NarReddit-Script-main folder?
have you double ckecked the file is named correctly? you can use the "dir" command in your terminal
yea it's .env not env
it needs to start with a dot
(that's why the lib is called dotenv)
ah right, I just assumed it was fine as it was a .env file type
however I just renamed It and I am still getting the same KeyError
and when I change the code to print(env) It's still not the output I'm expecting
what did you change the filename to?
.env like you said
that's not gonna fix anything
it does
sometimes environment variables are stored for future use
overriding it helps when you have replaced it with new values
It didn't work
that doesn't explain the keyerror
hmm weird
the var doesn't exist, and you shouldn't use override anyway, as actually specified env vars should have priority... the .env is just a fallback
anyway
so the file is named literally ".env" - only those 4 characters? (just making sure)
(".env" is not an extension, it's the full filename) ๐
yep
how can such a simple thing be so complicated haha
well , I have a feeling it's actually .env.txt ... can you use the "dir" command in your terminal to list the files?
it says .env.env
yea, that's wrong. it seems whatever you use to create the file with, adds it automatically
Can you do this, you should then be able to see the full name, .env.env in file explorer, and can then rename the file to .env
yep, always nicer to actually see all your extensions
I had a message typed out saying I'm guessing the files named .env.env lol
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ KeyError