设为首页收藏本站

Crossin的编程教室

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

【Python 第44课】 查天气(2)

  [复制链接]

0

主题

0

好友

16

积分

新手上路

Rank: 1

楼主
发表于 2018-3-11 11:25:19 |显示全部楼层
老师,我用的是py3.6
我的代码:
# -*- coding: utf-8 -*-
from city import city
import urllib.request
import json
cityname = input('你想查哪个城市的天气?\n')
citycode = city.get(cityname)
if citycode:
   url = ('http://www.weather.com.cn/data/cityinfo/%s.html' % citycode)
   content = urllib.request.urlopen(url).read()
   print(content)

结果报错:
  File "C:\Users\shenwang886\Desktop\python\从网络中获取数据.py", line 10, in <module>
    from city import city
  File "C:\Users\shenwang886\Desktop\python\city.py", line 2
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xb1 in position 0: invalid start byte

请问应该怎么改呢?
回复

使用道具 举报

0

主题

0

好友

16

积分

新手上路

Rank: 1

沙发
发表于 2018-3-11 15:51:59 |显示全部楼层
crossin先生 发表于 2018-3-11 15:41
两个文件开头都改成 gbk

问题已经解决了!
非常感谢指导
回复

使用道具 举报

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

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

GMT+8, 2024-5-16 04:19 , Processed in 0.021052 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部