设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
查看: 10481|回复: 0
打印 上一主题 下一主题

求助查天气[2]

[复制链接]

1

主题

0

好友

7

积分

新手上路

Rank: 1

跳转到指定楼层
楼主
发表于 2018-6-8 12:57:19 |显示全部楼层 |倒序浏览
【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, 下载次数: 309)

TQ.png

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-5-18 14:21 , Processed in 0.031613 second(s), 25 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部