所以我写了一个python应用程序来获取highcharts的股票数据。我在终端
中得到这个127.0.0.1 - - [28/Mar/2013 13:47:02] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [28/Mar/2013 13:47:02] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [28/Mar/2013 13:47:15] "GET /json/msft/?startdate=2010-01-01?enddate=2011-01-01 HTTP/1.1" 200 -
这是我的javascript代码
<script type="text/javascript">
function stock() {
console.log('pass 1')
url = 'http://127.0.0.1:5000/json/' + document.getElementById("ticker").value + '/?startdate=' + document.getElementById("startdate").value + '?enddate=' + document.getElementById("enddate").value
$.getJSON(url, function(data) {
console.log('pass 2')
// split the data set into ohlc and volume
var ohlc = [],
volume = [],
dataLength = data.length;
for (i = 0; i < dataLength; i++) {
ohlc.push([
data[i]["date"], // the date
data[i]["open"], // open
data[i]["high"], // high
data[i]["low"], // low
data[i]["close"] // close
]);
volume.push([
data[i]["date"], // the date
data[i]["volume"] // the volume
])
}
// set the allowed units for data grouping
var groupingUnits = [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]];
// create the chart
$('#container').highcharts('StockChart', {
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Historical'
},
yAxis: [{
title: {
text: 'OHLC'
},
height: 200,
lineWidth: 2
}, {
title: {
text: 'Volume'
},
top: 300,
height: 100,
offset: 0,
lineWidth: 2
}],
series: [{
type: 'candlestick',
name: 'AAPL',
data: ohlc,
dataGrouping: {
units: groupingUnits
}
}, {
type: 'column',
name: 'Volume',
data: volume,
yAxis: 1,
dataGrouping: {
units: groupingUnits
}
}]
});
});
}
</script>
和我的json请求的python代码
@app.route('/json/<ticker>/', methods = ['GET'])
def json_route(ticker):
startdate = request.args.get('startdate','')
enddate = request.args.get('enddate','')
check = datecheck(startdate,enddate)
if check != 'pass':
return check
check = datacheck(ticker,startdate,enddate)
if check != 'got data':
urldata(ticker)
print '-----------------data-----------------'
conn = engine.connect()
entries = conn.execute(select([Stocks]).where(Stocks.symbol == ticker ).where(Stocks.date.between(startdate,enddate))).fetchall()
stocklist = []
print entries
for x in entries:
stocklist.append({
'volume': float('%f' %x[7]),
'high': float('%.2f' %x[4]),
'open': float('%.2f' %x[3]),
'low': float('%.2f' %x[5]),
'close': float('%.2f' %x[6]),
'date': str(x[2]),
'stock': x[1],
})
conn.close()
return json.dumps(stocklist)
我做错了什么?我假设getjson在同一个域localhost上是可行的。只有console.log('pass one')工作,并在检查元素时显示在控制台中。传球二从未被击中。
答案 0 :(得分:4)
根据错误消息“仅支持HTTP ”来判断,它需要一个HTTP URL。你试过了吗?
url = 'http://127.0.0.1:5000/json/...