3-2中文编码报错如何解决?

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

Ssunyy

2017-04-20

# -*- 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('北京').encode('utf8')
print getweather(u'长春')

看了之前老师的解答改成了print getweather('北京').encode('utf8')形式,还是报错,我是在pycharm上运行的,不知道该如何解决?望老师解答,谢谢~~~

写回答

1回答

程序员硕

2017-04-20

贴一下错误log

0
4
Ssunyy
非常感谢!
2017-04-20
共4条回复

Python高效编程技巧实战

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

2582 学习 · 360 问题

查看课程