使用Python Flask框架,该脚本等待GET请求从此link获取json。该脚本可在localhost上完美运行,但是在HEROKU上部署时返回请求超时。
Heroku部署100%正常运行[测试]
这是我的代码:
import requests
from flask import Flask, request
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class Predictions(Resource):
def get(self):
url = 'https://stats.nba.com/stats/leaguedashteamstats?Conference=&DateFrom=&DateTo=&Division=&GameScope=&GameSegment=&LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PORound=0&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerExperience=&PlayerPosition=&PlusMinus=N&Rank=N&Season=2018-19&SeasonSegment=&SeasonType=Regular+Season&ShotClockRange=&StarterBench=&TeamID=0&TwoWay=0&VsConference=&VsDivision='
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'}
resp = requests.get(url, headers=headers)
data = resp.json()
resp.close();
return data
api.add_resource(Predictions, '/algpredictions')
if __name__ == '__main__':
app.run()