{"id":9396,"date":"2018-07-02T01:56:35","date_gmt":"2018-07-02T05:56:35","guid":{"rendered":"https:\/\/qxf2.com\/blog\/?p=9396"},"modified":"2018-07-02T01:56:35","modified_gmt":"2018-07-02T05:56:35","slug":"attributeerror-module-object-has-no-attribute-find_dotenv-while-running-flask-app","status":"publish","type":"post","link":"https:\/\/qxf2.com\/blog\/attributeerror-module-object-has-no-attribute-find_dotenv-while-running-flask-app\/","title":{"rendered":"AttributeError: &#8216;module&#8217; object has no attribute &#8216;find_dotenv&#8217; while running Flask app"},"content":{"rendered":"<p>We have a Flask app <a href=\"https:\/\/github.com\/qxf2\/cars-api\">&#8220;cars-api&#8221;<\/a> to help testers learn to write API automation. One day we hit across this issue while running the app<\/p>\n<blockquote><p>File &#8220;C:\/Git\/cars-api-master\/cars_app.py&#8221;, line 234, in <module><br \/>\n    app.run(host=&#8221;127.0.0.1&#8243;, port=5000)<br \/>\n  File &#8220;C:\\Python27\\lib\\site-packages\\flask\\app.py&#8221;, line 910, in run<br \/>\n    cli.load_dotenv()<br \/>\n  File &#8220;C:\\Python27\\lib\\site-packages\\flask\\cli.py&#8221;, line 600, in load_dotenv<br \/>\n    path = dotenv.find_dotenv(name, usecwd=True)<br \/>\nAttributeError: &#8216;module&#8217; object has no attribute &#8216;find_dotenv&#8217;\n<\/p><\/blockquote>\n<p>I looked at the issue and was confused since we were not using the dotenv module in our code. One of my colleague <a href=\"https:\/\/qxf2.com\/employees\/rohan\">Rohan Dudam<\/a> 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.<\/p>\n<p>For a permanent fix, I had a closer look at the error in detail which gave me some idea<\/p>\n<blockquote><p>File &#8220;C:\\Python27\\lib\\site-packages\\flask\\cli.py&#8221;, line 600, in load_dotenv<br \/>\n    path = dotenv.find_dotenv(name, usecwd=True)\n<\/p><\/blockquote>\n<p>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<\/p>\n<blockquote><p>pip install &#8211;upgrade python-dotenv\n<\/p><\/blockquote>\n<p>I changed my Flask version to the recent one and ran the cars_app.py again.<\/p>\n<p>Boom! The cars_app ran swiftly with an upgraded engine \ud83d\ude42<\/p>\n<p><strong>Note:<\/strong> We run our cars-app in <a href=\"https:\/\/circleci.com\/\">CircleCI<\/a> container to support our tests for <a href=\"https:\/\/github.com\/qxf2\/qxf2-page-object-model\">qxf2-page-object-model<\/a><\/p>\n<hr>\n<p>This article was produced by Qxf2 Services. Learn more <a href=\"https:\/\/qxf2.com\/blog\/about-qxf2\/\">about Qxf2 Services<\/a>.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>We have a Flask app &#8220;cars-api&#8221; to help testers learn to write API automation. One day we hit across this issue while running the app File &#8220;C:\/Git\/cars-api-master\/cars_app.py&#8221;, line 234, in app.run(host=&#8221;127.0.0.1&#8243;, port=5000) File &#8220;C:\\Python27\\lib\\site-packages\\flask\\app.py&#8221;, line 910, in run cli.load_dotenv() File &#8220;C:\\Python27\\lib\\site-packages\\flask\\cli.py&#8221;, line 600, in load_dotenv path = dotenv.find_dotenv(name, usecwd=True) AttributeError: &#8216;module&#8217; object has no attribute &#8216;find_dotenv&#8217; I looked at the [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,1],"tags":[],"class_list":["post-9396","post","type-post","status-publish","format-standard","hentry","category-python","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/9396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/comments?post=9396"}],"version-history":[{"count":12,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/9396\/revisions"}],"predecessor-version":[{"id":9452,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/9396\/revisions\/9452"}],"wp:attachment":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/media?parent=9396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/categories?post=9396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/tags?post=9396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}