编码报错,怎么破?

来源:3-2 如何实现可迭代对象和迭代器对象(2)

Lewi

2017-06-12

# -*- coding:utf-8 -*-
import requests
def getweather(city):
   r = requests.get(u'http://wthrcdn.etouch.cn/weather_mini?city=' + city)
   data = r.json()['data']['forecast'][0]
   return '%s: %s,%s' %(city, data['low'], data['high'])
print getweather(u'长春')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef
>>> import sys
>>> sys.getdefaultencoding()
'ascii'


写回答

1回答

程序员硕

2017-06-12

哪里运行的?

1
2
程序员硕
回复
Lewi
在本机上实验
2017-06-12
共2条回复

Python高效编程技巧实战

精选50个Python案例,源自实战,全面提升Python编程能力

2582 学习 · 360 问题

查看课程