我有一個燒瓶應用程式,它以引數形式從 url 中提取 3 個值,例如 - 股票代碼、開始日期、結束日期
我面臨的問題是,當我第一次點擊 url 時,它會正確回傳我的資料,盡管當我下次嘗試它同時更改引數的值時它不起作用
URL的標準格式-127.0.0.1:5000/api?ticker=IEX&start=25-04-2022&end=25-05-2022
盡管當我說將起始值從 25-04-2022 更改為 25-03-2022 引數時,代碼回傳的值與第一個引數相同。
這是我的代碼
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=["EQ"]&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 = {'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=["EQ"]&from={start}&to={end}"
result = s.get(api_url,headers=headers).json()
return result
if __name__ == "__main__":
app.run(debug=True, port=int(os.environ.get('PORT', 5000)))
uj5u.com熱心網友回復:
可能是因為你快取超時為0,所以快取設定為無限時間
@cache.cached(timeout=0)
嘗試注釋掉或洗掉以下行
cache = Cache(app)
@cache.cached(timeout=0)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/489807.html
