本文摘自php中文网,作者PHP中文网,侵删。
Yahoo重新开放了天气API,不使用oauth只能每天获取2000次/ip
使用oauth获取天气的python代码如下,使用了requests_oauthlib进行认证
使用oauth获取天气的次数为每小时2w次,每天10w次。
使用前请注册一个Yahoo的APP获得key
# sudo pip install requests requests_oauthlib
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import requests
from requests_oauthlib import OAuth1
consumerKey = <Your Consumer Key from Yahoo>
consumerSecret = <Your Consumer Secret from Yahoo>
baseurl = "https://query.yahooapis.com/v1/yql?"
yql_query = 'select * ' + 'from weather.forecast where woeid in'
yql_query + = ' (select woeid from geo.places(1) where text="%s") and u="c"' % "Beijing"
auth = OAuth1(consumerKey, consumerSecret)
result = requests.post(baseurl, data = { 'q' : yql_query, 'format' : 'json' }, auth = auth)
print result
print result.json()<br><br>
|
以上就是Yahoo Weather API with Oauth1的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python怎么移除字符串中的换行符
Python正则表达式详解,告诉你Python正则表达式是什么?
Python脚本生成caffe train_list.txt的方法
如何Python判断字符串是否为回文?
Python 实现在excel末尾增加新行
sqrt是什么函数
树莓派怎么运行Python程序
r vs. Python数据分析详解
Python列表如何去重
Python在文本开头插入一行的实例
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Yahoo Weather API with Oauth1