本文摘自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中安装虚拟环境virualenv的方法
什么是Python?你应该学习和使用它的13个理由
用Python实现高性能测试工具(二)
Python int函数怎么用
“foo is none”和“foo == none”有什么区别
Python的方法是什么
Python 多维切片之冒号和三个点
Python中flask的session设置的方法介绍
pycharm有没有中文版
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Yahoo Weather API with Oauth1