- 帖子
- 2
- 精华
- 0
- 积分
- 18
- 阅读权限
- 10
- 注册时间
- 2018-2-5
- 最后登录
- 2018-2-17
|
crossin先生 发表于 2018-2-12 22:30
拿到content后转化一下,content = content.decode('utf8')
老师,我按照您说的改了之后,print(content)时,又报错Traceback (most recent call last):
File "C:\Python3\weather.py", line 12, in <module>
content=content.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
我上网查说是去掉'Accept-Encoding':' gzip, deflate',但是程序里本来就没这句话啊。
附上代码- import urllib.request
- import json
- import urllib
- import io
- import gzip
- print('你想查哪个城市的天气')
- place=urllib.parse.quote(input())
- url='http://wthrcdn.etouch.cn/weather_mini?city=%s'%place
- content=urllib.request.urlopen(url).read()
- content=content.decode('utf-8')
- print (content)
复制代码 |
|