Ask coding questions

← Back to all posts
How do I keep a json file private without having to by the premium plan.
Quackalicious (0)

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.

Comments
hotnewtop
robowolf (556)

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.

Quackalicious (0)

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

Coder100 (19280)

You can use first turn the json into one line, and then paste it into a key, like this:

then when you access it, all you have to do is:

Quackalicious (0)

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

Coder100 (19280)

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

Quackalicious (0)

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

Quackalicious (0)

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

Quackalicious (0)

@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

Coder100 (19280)

ur .env looks like this:

and you access it like this:

@Quackalicious

Quackalicious (0)

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

Coder100 (19280)

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

Quackalicious (0)

@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

Coder100 (19280)

invited you to the working repl @Quackalicious

Quackalicious (0)

@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

Coder100 (19280)

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

Quackalicious (0)

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

Coder100 (19280)

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

https://replit.com/bugs @Quackalicious

Quackalicious (0)

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

Quackalicious (0)

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

bryanfks (0)

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

Coder100 (19280)

what

would you like me to invite you to a repl? @bryanfks-dev

bryanfks (0)

@Coder100 sure that would be a big help !

bryanfks (0)

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

bryanfks (0)

So when will you invite me into your repl? @Coder100

Coder100 (19280)

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

bryanfks (0)

Okayy I already invite you into my repl @Coder100