jgrugru / encrypto-env

Easily setup your Python .env file with encryption.
MIT License
3 stars 0 forks source link

list index out of range when executing EnvFile().create_environment_variables() #4

Open carlosgrillet opened 2 years ago

carlosgrillet commented 2 years ago

I'm trying to test if I can securely store my db credentials using this lib. This is my code

from encryptoenv.EnvFile import EnvFile
from os import environ

EnvFile().create_environment_variables()

print(environ["DB_USERNAME"])
print(environ["DB_PASSWORD"])

When I try to run the code it give me this output:

Traceback (most recent call last):
  File "/home/carlos/os_test.py", line 5, in <module>
    EnvFile().create_environment_variables()
  File "/home/carlos/.local/lib/python3.10/site-packages/encryptoenv/EnvFile.py", line 75, in create_environment_variables
    self.set_environment_variable(
  File "/home/carlos/.local/lib/python3.10/site-packages/encryptoenv/EnvFile.py", line 71, in set_environment_variable
    environ[variable[0]] = variable[1]
IndexError: list index out of range

I already create the variables using encryptoenv CLI

$ encryptoenv -l
DB_USERNAME

DB_PASSWORD

DB_NAME
jgrugru commented 2 years ago

Hi @carlosgrillet, I am busy today, but will have time to take a look tomorrow. I haven't touched this project in some time, so there may be some weird bugs. I'll get back to you once I take a look.

jgrugru commented 2 years ago

@carlosgrillet I was able to get it working on my own machine. When you run encryptoenv -D does your .env file look correct? Mine looks like this:

PASSWORD=TESTINGff
DB_PASSWORD=12345jgjajd4%
DB_NAME=145jgjajd4%

It could be that the .env file is not formatted correctly or that there are certain characters in your env file variables that I didn't account for, causing errors. Glad to help more if needed.

Pyenb commented 1 year ago

Hey there, I am currently facing the same problem:

PS C:\xxx> python .\test.py         
Traceback (most recent call last):
  File "C:\xxx\test.py", line 3, in <module>
    EnvFile().create_environment_variables()
  File "C:\Users\xxx\AppData\Roaming\Python\Python310\site-packages\encryptoenv\EnvFile.py", line 75, in create_environment_variables
    self.set_environment_variable(
  File "C:\Users\xxx\AppData\Roaming\Python\Python310\site-packages\encryptoenv\EnvFile.py", line 71, in set_environment_variable
    environ[variable[0]] = variable[1]
IndexError: list index out of range

When decryptiong the file, the .env is empty. I generated it with encryptoenv --dot-env-file .env -E. Maybe you got a fix for that. My .env file should be formatted correctly. But don't worry, if you abandoned the project or anything, I will find another solution.

guerralindao commented 1 year ago

Hello @Pyenb, @jgrugru,

do you change the previous variables? Because I did that and I got the same error:

$ encryptoenv -a "**TEST1**=Ciao@2023!" -E
$ encryptoenv -a "**TEST1**=Ciao23!" -E

After I changed the previous variable "TEST1" :

Traceback (most recent call last):
  File "/xxxx/BotTelegramAffiliate/EnvTest.py", line 4, in <module>
    EnvFile().create_environment_variables()
  File "/xxxx/BotTelegramAffiliate/venv/lib/python3.10/site-packages/encryptoenv/EnvFile.py", line 75, in create_environment_variables
    self.set_environment_variable(
  File "/xxxx/BotTelegramAffiliate/venv/lib/python3.10/site-packages/encryptoenv/EnvFile.py", line 71, in set_environment_variable
    environ[variable[0]] = variable[1]
IndexError: list index out of range

I didn't find a solution.. The problem is when I'm trying to define again the variable "TEST1" after execute the below command:

$ encryptoenv --clear

Maybe is there something regarding cache dir? Do you found another solution?

Thanks