AttributeError: ‘module’ object has no attribute ‘find_dotenv’ while running Flask app

We have a Flask app “cars-api” to help testers learn to write API automation. One day we hit across this issue while running the app

File “C:/Git/cars-api-master/cars_app.py”, line 234, in
app.run(host=”127.0.0.1″, port=5000)
File “C:\Python27\lib\site-packages\flask\app.py”, line 910, in run
cli.load_dotenv()
File “C:\Python27\lib\site-packages\flask\cli.py”, line 600, in load_dotenv
path = dotenv.find_dotenv(name, usecwd=True)
AttributeError: ‘module’ object has no attribute ‘find_dotenv’

I looked at the issue and was confused since we were not using the dotenv module in our code. One of my colleague Rohan Dudam pointed out that the issue was happening in the recent Flask version which was 1.0.2. The code used to work fine in 0.12.2. I made a temp fix to revert the Flask version to older version.

For a permanent fix, I had a closer look at the error in detail which gave me some idea

File “C:\Python27\lib\site-packages\flask\cli.py”, line 600, in load_dotenv
path = dotenv.find_dotenv(name, usecwd=True)

The cli.py file tries to load find_dotenv method from dotenv. This method was missing from my dotenv file. I upgraded the python-dotenv to a recent version

pip install –upgrade python-dotenv

I changed my Flask version to the recent one and ran the cars_app.py again.

Boom! The cars_app ran swiftly with an upgraded engine 🙂

Note: We run our cars-app in CircleCI container to support our tests for qxf2-page-object-model


This article was produced by Qxf2 Services. Learn more about Qxf2 Services.


3 thoughts on “AttributeError: ‘module’ object has no attribute ‘find_dotenv’ while running Flask app

  1. Hello All, if this does not work for you. then you can try this —>pip install python-dotenv==0.10.1 (latest version of dotenv)

Leave a Reply

Your email address will not be published. Required fields are marked *