2

In Pset8, I continue to get the "API_KEY" not set runtime error, even though i crosschecked with:

echo $API_KEY

and the response was:

AIzaSyDKcW1m49qo95kiJFTpGWTUrj3Iyi-xloA

which matched the key that i exported. Read the answer below to understand how to fix this ANNOYING bug.

1
  • Glad I could help Jeremy! Commented Sep 1, 2017 at 16:02

3 Answers 3

8

This can be easily solved by noting which terminal the export command was executed in the same terminal window that flask is running in (will be prompted to run in after the export command). Otherwise, flask cannot recognize the API_KEY as an environment variable, hardly being an environment variable.

4
  • 1
    Thanks Karthik :) Commented Aug 31, 2017 at 16:29
  • np ;) i suffered too long for this on pset 8 Commented Oct 26, 2017 at 4:47
  • 1
    thanks Karthik. You suffered so we didn't have to. Commented Oct 26, 2017 at 9:15
  • how should i export the api_key if I am doing the same pset on vscode?
    – Praful
    Commented Jun 21, 2019 at 17:03
1

If anyone is still having a problem to set API_KEY as an environmental variable, remember to do it following this syntax (in VSCODE terminal or powershell for WINDOWS):

$env:API_KEY="YOUR-API-KEY-HERE"

Then flask run

Also, remember to do this in the same directory in which the app is located, and to also previously set 'application' (as long as it still is the name of your main .py file) as the environment in which the Flask app runs, as per the following syntax: $env:FLASK_APP = "application"

0
0

For those that didn't understand the answer of @Karthik Krishnan you can follow this:

export API_KEY=...

Where ... is the api key you got from IEX Cloud

after this in the same terminal window do:

flask run

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .