I am getting this error when i hit this URL - "https://arthavruksha.pythonanywhere.com/api?ticker=IEX&start=25-04-2022&end=25-05-2022" which works fine on Local Machine although not on pythonanywhere. Here's my Code-
import requests
from datetime import date
import time
import json
import pandas as pd
import os
from flask import Flask
from flask_caching import Cache
from flask import request
config = {
"CACHE_TYPE": "SimpleCache", # Flask-Caching related configs
"CACHE_DEFAULT_TIMEOUT": 0,
}
app = Flask(__name__)
# tell Flask to use the above defined config
app.config.from_mapping(config)
cache = Cache(app)
@app.route("/api")
@cache.cached(timeout=0)
def index():
# https://www.nseindia.com/api/historical/cm/equity?symbol=IEX&series=[%22EQ%22]&from=25-04-2022&to=25-05-2022
ticker = request.args.get( 'ticker', None)
start = request.args.get( 'start', None) #25-04-2022
end = request.args.get( 'end', None) #25-05-2022
s = requests.Session()
# headers = {'user-agent':'Mozilla/5.0 (Wind1ows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'}
headers = {'Host':'www.nseindia.com', 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Language':'en-US,en;q=0.5', 'Accept-Encoding':'gzip, deflate, br','DNT':'1', 'Connection':'keep-alive', 'Upgrade-Insecure-Requests':'1','Pragma':'no-cache','Cache-Control':'no-cache', }
url = 'https://www.nseindia.com/'
step = s.get(url,headers=headers)
api_url = f"https://www.nseindia.com/api/historical/cm/equity?symbol={ticker}&series=[%22EQ%22]&from={start}&to={end}"
result = s.get(api_url,headers=headers).json()
return result