作者purplvampire (阿修雷)
看板Python
标题[问题] 网页抓不下来
时间Sat Jun 8 22:50:38 2019
各位前辈大大好:
我在练习抓天气网站的资料,可是照着API教学却出现错误讯息,
请大大帮忙看一下是哪边做错,感谢~
程式码:
location = ' '.join(sys.argv[1:])
# Download the JSON data from OpenWeatherMap.org's API.
url = '
http://api.openweathermap.org/data/2.5/forecast/daily?q=%s&cnt=3' %
(location)
response = requests.get(url)
response.raise_for_status()
错误讯息:
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url:
http://api.openweathermap.org/data/2.5/forecast/daily?q=Taipei&cnt=3
天气网站API设定教学:
https://openweathermap.org/forecast16
Examples of API calls: Call 7 days forecast by city name
api.openweathermap.org/data/2.5/forecast/daily?q=London&cnt=7
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 180.177.123.190 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1560005445.A.0B6.html
1F:→ vi000246: 可能要收费吧 你去看文件 应该是没取得授权 06/08 23:30
2F:→ InfinityGate: API KEY... 06/08 23:52
3F:→ Hsins: Unauthorized 不就很明显ㄌ? 06/09 01:04
喔喔,谢谢各位大大释疑,还真的要注册拿key才能用
https://openweathermap.org/appid
※ 编辑: purplvampire (180.177.123.190 台湾), 06/09/2019 10:30:06