Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
read_dotenv problem
#1
Hi

I am working with some sample code from ciscoAxl sdk

part of the sample code is this:

import os #for ciscoaxl sdk
from ciscoaxl import axl #for ciscoaxl sdk
from py_dotenv import read_dotenv
dotenv_path = os.path.join(os.path.dirname(__file__), '.env') #orig
read_dotenv(dotenv_path)
however when I run that, I get the following error.

Error:
Traceback (most recent call last): File "C:\Users\itsMe\eclipsePython-workspace\PythonTestMod\Demo.py", line 4, in <module> read_dotenv(dotenv_path) File "C:\Users\itsMe\AppData\Local\Programs\Python\Python36-32\lib\site-packages\py_dotenv\dotenv.py", line 10, in read_dotenv 'Not loading {} - it doesn\'t exists'.format(file_path) FileNotFoundError: Not loading C:\Users\itsMe\eclipsePython-workspace\PythonTestMod\.env - it doesn't exists
I tried it with quotes around the file "__file__" as suggested in a post somewhere but no luck.

It looks like it is returning most of the environment path, but I dont know what it is looking for with the .env at the end.

Can anyone give any suggestions?
thanks
Reply
#2
it can't find the .env file
Reply
#3
yes. but what .env is it looking for? and how do I get it?
Is it something that should have installed with python? I assume there should be more to the name than .env but there is nothing to show what that would be.

The code is from examples.py for ciscoaxl by levensailor and can be viewed on github.
Im new to python and Im not sure if I should be chasing this from the python perspective or the ciscoaxl perspective.

thanks for your help
Reply
#4
In the future it would be nice to include link to github repo - it helps a lot
https://github.com/levensailor/ciscoaxl/...xamples.py

.env file is used to provide application settings via Environmental variables.
python-dotenv reads that file and exports the provided settings as Environmental variables
then look at the examples.py
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
read_dotenv(dotenv_path)

cucm = os.getenv('cucm')
username = os.getenv('username')
password = os.getenv('password')
version = os.getenv('version')
as you can see, the scripts reads cucm, username, password and version from the environment variables.
check python-dotenv docs for specific instructions for .env file format

https://github.com/theskumar/python-dotenv
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Hi Buran, Thanks for the information - I will run down that route.

and Thanks for the tip on including the link - I had considered it but was thinking I saw a warning against including links in the rules - but I have signed up in a few different forums since starting work on this project and I may have confused the rules from another forum.

I will let you know how it goes

Buran! Awesome! that provided the information I needed! I am past that roadblock (only a few hundred more to go...) Thanks a ton!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020