如何解决新浪微博返回结果中的中文编码问题

# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#新浪微博api研究


#设置accsess_token,client可以直接调用API了


#根据用户ID获取用户信息
#请求方式:get
#https://api.weibo.com/2/users/show.json
#注意该url中间有一个2,这样的url一般可以用下面的方式来运用api。
get_results = client.users__show(uid='1949305184')  #1949305184是微博桌面
print 'ID:',get_results.id                             #ID: 1949305184
print 'Name:',get_results.screen_name.encode('utf-8')  #Name: 微博桌面
print 'OK'

解决办法:result.encode('utf-8')即可

posted @ 2015-10-31 10:27  Xiao|Deng  阅读(380)  评论(0编辑  收藏  举报