本文摘自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的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
numpy api analysis
Python解释器怎么运行
Python数据类型的区别
Python的用途有哪些?
Python装饰器以什么开头
Python web开发用什么工具
学Python用什么电脑
Python更改已存在excel文件的方法
Python类怎么定义
Python循环嵌套是什么?(代码示例)
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Yahoo Weather API with Oauth1