Skip to content
Sign upLog in
← Back to Community

How do I keep a json file private without having to by the premium plan.

Profile icon
Quackalicious

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.

Voters
Profile icon
FarshidMaleki
Profile icon
Quackalicious
Comments
hotnewtop
Profile icon
robowolf

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.

Profile icon
Quackalicious

@robowolf
Thanks! I'll definitely check out the encryption method!

Profile icon
robowolf

@Quackalicious
Np.

Profile icon
LuizEduardo69

Para quem quer algo menor tem esse:
credentials = json.loads(os.getenv("key"))
com carregar com dicionario

Profile icon
Coder100

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")))
Profile icon
Quackalicious

@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.

Profile icon
Coder100

Of course not, .env files are literally private to others
https://docs.repl.it/repls/secret-keys


@Quackalicious

Profile icon
Quackalicious

@Coder100
ohhhhh now i see what you mean, okay but still what do you mean turn the json into one line

Profile icon
Quackalicious

@Quackalicious
Okay I am a certified idiot, I finally understand, sry if I was a nuisance.

Profile icon
Coder100

lmao no worries

@Quackalicious

Profile icon
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

Profile icon
Coder100

ur .env looks like this:

KEY=ababa

and you access it like this:

import os key = os.getenv("KEY") # key is now ababa

@Quackalicious

Profile icon
Quackalicious

@Coder100
k thank u so much

Profile icon
Quackalicious

So when i try and print the key in main.py its supposed to say None right?

Profile icon
Coder100

no, because you are the owner so you can access .env

@Quackalicious

Profile icon
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

Profile icon
Coder100

did you do it wrong?

@Quackalicious

Profile icon
Coder100

invited you to the working repl

@Quackalicious

Profile icon
Quackalicious

@Coder100
okay

Profile icon
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

Profile icon
Coder100

well of course, if you aren't the owner you can't access .env, meaning others can't run the program at all

@Quackalicious

Profile icon
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.

Profile icon
Coder100

no no
it's actually a replit bug where the .env file isn't read!!

https://replit.com/bugs

@Quackalicious

Profile icon
Quackalicious

oh really? I wasted so much time for dang bug. Well thx anyways or else i probably would have wasted even more time

Profile icon
Quackalicious

Wait but then how did it work for you? the example you showed me worked.

Profile icon
bryanfks

@Coder100
can I know more about this? I already did this, but I'm kinda confused about your GoogleSheetsApiTest in main.py, well you already declare the key variable, but you don't use it in your code. Btw I'm working on google API too, so can you show me how to fix it?

Profile icon
Coder100

what

would you like me to invite you to a repl?

@bryanfks-dev

Profile icon
bryanfks

@Coder100
sure that would be a big help !

Profile icon
bryanfks

@Coder100
oh sorry, when I looked back, I realized the GoogleSheetsApiTest is quackalicious's not yours lol

Profile icon
Coder100

lol

@bryanfks

Profile icon
bryanfks

So when will you invite me into your repl?

@Coder100

Profile icon
Coder100

@bryanfks
oops i wrote that wrong i meant you invite me to your repl in question

Profile icon
bryanfks

Okayy I already invite you into my repl

@Coder100

Profile icon
LuizEduardo69

@bryanfks
Para quem quer algo menor tem esse:
credentials = json.loads(os.getenv("key"))
com carregar com dicionario