After I tried with try: and except: which did not work, I tried another approach with requests library. Now in result I always get the else: statement what didn't work before but never the actual url even the variable stock exists.
Actually it's kind of clear. Within my if statement I don't refer to my variable request. If I refer to the variable request of course I cannot use .status_codes.
import requests
import pandas as pd
print("EMA PER WEEK - Exponential Moving Average | reacts more quickly to course data than f.e SMA (Simple Moving Average")
stock = input("Please enter a ticker symbol: ")
url = f"https://www.alphavantage.co/query?function=EMA&symbol={stock}&interval=weekly&time_period=10&series_type=open&apikey=MyAPI"
request = requests.get(url)
if requests.status_codes == 200:
data = request.json()
df= pd.DataFrame(data)
pd.set_option('display.max_columns',37)
print(df.head(37))
else:
print("Stock does not exists")
print(input("Please enter another ticker: "))
Aucun commentaire:
Enregistrer un commentaire