设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: crossin先生
打印 上一主题 下一主题

【Python 第45课】 查天气(3)

[复制链接]

0

主题

0

好友

20

积分

新手上路

Rank: 1

楼主
发表于 2016-3-5 10:06:50 |显示全部楼层
Traceback (most recent call last):
  File "C:\Users\admin\py实验\weather\weather.py", line 16, in <module>
    data=json.loads(content)
  1. from urllib import request
  2. from city import city

  3. print('你想查询哪个城市的天气?')
  4. cityname=input()
  5. citycode=city.get(cityname)
  6. if citycode:
  7.    
  8.     url = 'http://www.weather.com.cn/data/cityinfo/%s.html' % citycode
  9.     web=request.urlopen(url)
  10.     content=str(web.read())
  11.     print(type(content))
  12.     print(content)

  13.     import json
  14.     data=json.loads(content)
  15.     print(data)
复制代码
File "C:\Python34\lib\json\__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "C:\Python34\lib\json\decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)
回复

使用道具 举报

0

主题

0

好友

20

积分

新手上路

Rank: 1

沙发
发表于 2016-3-5 10:59:41 |显示全部楼层
crossin先生 发表于 2016-3-5 10:30
content好像是none没取到值。你确认下每一步的值。你用的python3吧,可能有些函数用法不一样 ...

是的,python3有很多不懂的地方也查不到教程,为了更好地学习,现在已经换成了python27,谢谢您!
回复

使用道具 举报

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

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

GMT+8, 2024-5-12 04:06 , Processed in 0.030861 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部