How do I keep a json file private without having to by the premium plan.
I'm new here to repl.it and I have been coding in python for a bit. I'm trying to connect my python code with my google API and spreadsheets but I also have a JSON file I need to use for that. I'm pretty sure I have to keep that private but I'm not sure how. Please help this is putting a stop to something I've been working on for a long time.
You can use first turn the json into one line, and then paste it into a key, like this:
#.env KEY={"a":"...","b":"..."}
then when you access it, all you have to do is:
import json import os print(json.loads(os.getenv("KEY")))
@Coder100 what do you mean one line. also that method looks like everyone would be able to see the key. I am trying to make it so people can not see the key because it is private.
Of course not, .env files are literally private to others
https://docs.repl.it/repls/secret-keys
@Quackalicious
@Coder100 ohhhhh now i see what you mean, okay but still what do you mean turn the json into one line
@Quackalicious Okay I am a certified idiot, I finally understand, sry if I was a nuisance.
lmao no worries @Quackalicious
@Coder100 wait, I think I'm still an idiot sry, how do I put the key into the encrypter. like lets say my key was ababa. what would i do for that
ur .env looks like this:
KEY=ababa
and you access it like this:
import os key = os.getenv("KEY") # key is now ababa
@Coder100 k thank u so much
So when i try and print the key in main.py its supposed to say None right?
no, because you are the owner so you can access .env @Quackalicious
@Coder100 okay so look I pasted the exact same code into my reply and when I tried to print the variable key like the key not KEY, it came up as none
did you do it wrong? @Quackalicious
invited you to the working repl @Quackalicious
@Quackalicious I literally copied and pasted what you ha in your repl into mine and it doesn't work https://replit.com/@Quackalicious/Test#main.py
well of course, if you aren't the owner you can't access .env, meaning others can't run the program at all @Quackalicious
@Coder100 no but I mean I put the code into my own thing which I am the owner of. I feel like I'm bothering you too much, sry. I'll find out how to do it myself.
no no
it's actually a replit bug where the .env file isn't read!!
oh really? I wasted so much time for dang bug. Well thx anyways or else i probably would have wasted even more time
Wait but then how did it work for you? the example you showed me worked.
what
would you like me to invite you to a repl? @bryanfks-dev
I've also tried to use google spreadsheets on repl. Sadly there is no way to conceal a JSON file. What you could do is find some components of the JSON file that you could put in a .env for later use. Another way to do it is obfuscation, which means you could encrypt it (https://qvault.io/2020/02/06/aes-256-cipher-python-cryptography-examples/) and store the encryption in a .env file. Then you can decrypt it when you need to use it. Any methods using a .env cannot be used by other people unless they are in a multiplayer.
@robowolf Thanks! I'll definitely check out the encryption method!
@Quackalicious Np.