Crossin的编程教室
标题:
求助查天气[2]
[打印本页]
作者:
419416340
时间:
2018-6-8 12:57
标题:
求助查天气[2]
【Python 第44课】 查天气(2)
中
在pycharm中运行
# -*- coding: utf-8 -*-
import
urllib2
import
json
from
city
import
city
cityname =
raw_input
(
'你想查哪个城市的天气?
\n
'
)
citycode = city.get(cityname)
if
citycode:
url = (
'http://www.weather.com.cn/data/cityinfo/%s.html'
% citycode)
content = urllib2.urlopen(url).read()
print
(content)
你想查哪个城市的天气?
北京
Traceback (most recent call last):
File "D:/Python31/pycharm/NEW/��������.py", line 10, in <module>
content = urllib2.urlopen(url).read()
File "D:\python27\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "D:\python27\Python27\lib\urllib2.py", line 435, in open
response = meth(req, response)
File "D:\python27\Python27\lib\urllib2.py", line 548, in http_response
'http', request, response, code, msg, hdrs)
File "D:\python27\Python27\lib\urllib2.py", line 473, in error
return self._call_chain(*args)
File "D:\python27\Python27\lib\urllib2.py", line 407, in _call_chain
result = func(*args)
File "D:\python27\Python27\lib\urllib2.py", line 556, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: Forbidden
Process finished with exit code 1
一直出现这样的错误,求大神指点迷津
TQ.png
(51.02 KB, 下载次数: 430)
2018-6-8 12:41 上传
点击文件名下载附件
作者:
crossin先生
时间:
2018-6-9 00:23
把url输出出来看看是什么
是不是地址失效了
查天气1开头有给出几个新接口
欢迎光临 Crossin的编程教室 (https://bbs.crossincode.com/)
Powered by Discuz! X2.5