0

I want to import my credentials from a .env file as this is a much more secure way.

I cant find instructions on the documentation: https://pypi.org/project/python-dotenv/ and similar question cant also help: Python to fetch LDAP credentials from JSON file

but basically I have and json variable ard code that it is currently working:

payload = {
    'client_id': "12345",
    'client_secret': 'a1234567803972de4472',
    'refresh_token': 'c123456755647353200eae76387d8c47f52',
    'grant_type': "refresh_token",
    'f': 'json' }

Changed for security

I want to have those in a .env file and to import it just like that.

res = requests.post(auth_url, data=payload, verify=False)
access_token = res.json()['access_token']

thanks in andvance!

dellaklo
  • 33
  • 1
  • 6

1 Answers1

1

Make sure the .env file is in the root of your project.

Do Not add the quotation string in the environment variable value.

Do Not add extra spaces between key=value

Your .env file should look like the sample below.

client_id=12345
client_secret=a1234567803972de4472

Lastly, in your python file, to load the .env file.

from dotenv import dotenv_values

config = dotenv_values(".env")
collinsuz
  • 439
  • 1
  • 4
  • 13