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/”, line 234, in”″, port=5000)
File “C:\Python27\lib\site-packages\flask\”, line 910, in run
File “C:\Python27\lib\site-packages\flask\”, 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\”, line 600, in load_dotenv
path = dotenv.find_dotenv(name, usecwd=True)

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

Avinash Shetty

I am a software tester with over 10 years of experience in software testing. Currently I am working at Qxf2 Services Bangalore. As a student of the context-driven approach to software testing I feel there is a lot to learn out there which keeps me very excited. My work has helped me gain good experience in different areas of testing like CRM, Web, Mobile and Database testing. I have good knowledge of building test scripts using Automation tools like Selenium and Appium using Java and Python. Beside testing I am a “Sports Fanatic” and love watching and playing sports.

One Comment

  1. Aarav Gotra said:

    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)

    January 31, 2019

Leave a Reply

Your email address will not be published.