鱼C论坛

 找回密码
 立即注册
查看: 1922|回复: 4

课时31 可以执行,但是输入就错误!

[复制链接]
发表于 2017-10-12 18:50:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
大神帮忙看看,我真的研究了好久!
import urllib.request
import json
city = {
    '北京':'101010100',
    '海淀':'101010200',
    '朝阳':'101010300',
    '顺义':'101010400',
    '怀柔':'101010500',
    '通州':'101010600',
    '延庆':'101010800',
    '石景山':'101011000',
    '大兴':'101011100',
    '房山':'101011200',
    '密云':'101011300',
    '门头沟':'101011400',
    '平谷':'101011500',
    '八达岭':'101011600',
    '佛爷顶':'101011700',
    '汤河口':'101011800',
    '密云上甸子':'101011900',
    '斋堂':'101012000',
    '霞云岭':'101012100',
    }

password = input('请输入城市:')
name1 = city[password]
File1 = urllib.request.urlopen('http://m.weather.com.cn/data/'+ name1+'.html')
weatherHTML = File1.read().decode('utf-8')
weatherJSON = json.JSONDecoder().decode(weatherHTML)
weatherInfo = weatherJSON['weatherinfo']

print('城市:',weatherInfo['city'])
print('时间:',weatherInfo['date_y'])
print('24小时天气:')
print('温度:',weatherInfo['temp1'])
print('天气:',weatherInfo['weather1'])
print('风速:',weatherInfo['wind1'])
print('紫外线:',weatherInfo['index_uv'])
print('穿衣指数:',weatherInfo['index_d'])
print('48小时天气:')
print('温度:',weatherInfo['temp2'])
print('天气:',weatherInfo['weather2'])
print('风速:',weatherInfo['wind2'])
print('紫外线:',weatherInfo['index48_uv'])
print('穿衣指数:',weatherInfo['index48_d'])
print('72小时天气:')
print('温度:',weatherInfo['temp3'])
print('天气:',weatherInfo['weather3'])
print('风速:',weatherInfo['wind3'])
input('按任意键退出:')

这个代码为什么会执行错误?
错误代码如下:
请输入城市:北京
Traceback (most recent call last):
  File "C:/Users/dell/AppData/Local/Programs/Python/Python36-32/5555555.py", line 26, in <module>
    File1 = urllib.request.urlopen('http://m.weather.com.cn/data/'+ name1+'.html')
  File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 532, in open
    response = meth(req, response)
  File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 570, in error
    return self._call_chain(*args)
  File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "C:\Users\dell\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden





小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-10-12 19:18:44 | 显示全部楼层
那个网址现在好像是禁止访问。你可以手动访问看看。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-10-12 19:22:08 | 显示全部楼层
重新去 抓包吧weather.com.cn
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-10-13 13:16:58 | 显示全部楼层
ba21 发表于 2017-10-12 19:22
重新去 抓包吧weather.com.cn

我不会啊,你能帮我看看吗?

www.nmc.cn中央气象网,我输入进去不对啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-10-13 13:17:36 | 显示全部楼层
啊哈123 发表于 2017-10-12 19:18
那个网址现在好像是禁止访问。你可以手动访问看看。

手动访问?

麻烦你给我看看!
谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-24 09:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表