- 帖子
- 1
- 精华
- 0
- 积分
- 7
- 阅读权限
- 10
- 注册时间
- 2018-6-8
- 最后登录
- 2018-6-11
|
【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
一直出现这样的错误,求大神指点迷津
|
|