gpt4 book ai didi

Python、yahoo yql 引用错误

转载 作者:行者123 更新时间:2023-11-28 16:35:09 24 4
gpt4 key购买 nike

我使用了 yql 控制台并收到了适当的响应。但是,发送基于 python 的查询时,我仍然遇到错误。首先是控制台示例:

select * from yahoo.finance.quotes where symbol in ("yahoo", "aapl")

我收到一个包含预期字段的结果 block 。 python 例子:

import requests
base_url = 'https://query.yahooapis.com/v1/public/yql?'
query = 'q=select * from yahoo.finance.quotes where symbol in ("YHOO", "AAPL")'
full_query=base_url + query
result = requests.get(full_query)
print(result.content)

响应如下:

b'\n找不到表 yahoo.finance.quotes' 的定义

我错过了什么?TIA,克莱顿

最佳答案

您缺少的是查询的 env 部分:

import json
import urllib
from pprint import pprint

base_url = 'https://query.yahooapis.com/v1/public/yql?'
query = {
'q': 'select * from yahoo.finance.quote where symbol in ("YHOO","AAPL")',
'format': 'json',
'env': 'store://datatables.org/alltableswithkeys'
}

url = base_url + urllib.urlencode(query)
response = urllib.urlopen(url)
data = response.read()
quote = json.loads(data)
pprint(quote)

输出:

{u'query': {u'count': 2,
u'created': u'2014-12-06T03:53:23Z',
u'lang': u'en-US',
u'results': {u'quote': [{u'AverageDailyVolume': u'38009400',
u'Change': u'+0.58',
u'DaysHigh': u'51.25',
u'DaysLow': u'50.51',
u'DaysRange': u'50.51 - 51.25',
u'LastTradePriceOnly': u'50.99',
u'MarketCapitalization': u'48.305B',
u'Name': u'Yahoo! Inc.',
u'StockExchange': u'NasdaqNM',
u'Symbol': u'YHOO',
u'Volume': u'15418123',
u'YearHigh': u'52.62',
u'YearLow': u'32.15',
u'symbol': u'YHOO'},
{u'AverageDailyVolume': u'57049800',
u'Change': u'-0.49',
u'DaysHigh': u'116.08',
u'DaysLow': u'114.64',
u'DaysRange': u'114.64 - 116.08',
u'LastTradePriceOnly': u'115.00',
u'MarketCapitalization': u'674.5B',
u'Name': u'Apple Inc.',
u'StockExchange': u'NasdaqNM',
u'Symbol': u'AAPL',
u'Volume': u'38318896',
u'YearHigh': u'119.75',
u'YearLow': u'70.5071',
u'symbol': u'AAPL'}]}}}

关于Python、yahoo yql 引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27327910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com