I have some env vars which should be loaded when the the specific func triggers, but when I run the main.py in Pycharm it does not work and gives the below error:
'Error Message': 'the parameter apikey is invalid or missing'
I have exported the env var in terminal:
$ export ALPHAVANTAGE_API_KEY=1qa2ws3ed4rf5t
and checked the env to see if it is there.
and tried to get it in the code:
alphavantage_api_key = os.environ.get("ALPHAVANTAGE_API_KEY")
but it gives me error, the interesting thing is if I run the main.py in terminal or hard coded the API-Key, everything works perfectly.
this is the code:
import os
import requests
# variables
STOCK = "something"
COMPANY_NAME = "something"
alphavantage_url = 'https://www.alphavantage.co/query'
alphavantage_api_key = os.environ.get("ALPHAVANTAGE_API_KEY")
alphavantage_parameters = {
'function': 'TIME_SERIES_DAILY',
'symbol': STOCK,
'apikey': alphavantage_api_key,
'datatype': 'json'
}
# Getting info from AlphaVantage
response = requests.get(alphavantage_url, params=alphavantage_parameters)
response.raise_for_status()
response.json()
print(response.json())