简体   繁体   中英

How can i set up credentials as an environmental variable in windows?

I'm currently working on an academic project in my university and im trying to access IEX Cloud API (iexfinance) for financial data extraction using python but i keep running into an authentication error. When i checked the documentation of the package it recommends to set Secret Authentication Key as an environmental variable using 'IEX_TOKEN' to authenticate my request which i dont know how to do.

Also, i should note that i'm very new to the world of programming so thank you in advance for any assistance.

Here's a snippet of the script i use:

tickerSymbol = input("Ticker Symbol: ")
companyInfo = Stock(tickerSymbol)
stockPrice = companyInfo.get_price()

start = datetime(sy,sm,sd)
end = datetime(ey, em,ed)

historicalPrices = get_historical_intraday(tickerSymbol, start, end)

stockHistoricals = pd.DataFrame(historicalPrices).T

Assuming you know the secret authentication key. Try:

#import os module in first line of your code
import os
#set the env vairable in 2nd line
os.environ['IEX_TOKEN'] = 'TheSecretAuthenticationKey'

#other imports
...
...
...
...
#remaining code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM