【发布时间】:2016-11-27 02:41:57
【问题描述】:
我想使用 lib: tweepy 提取一些推文。在打印数据时,它给出了错误 UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1 然后我 decode 它使用 .decode('utf-8') 。但是过了一会儿,为了人性化阅读,我想用.decode('utf-8')decode它,但它不起作用。
import tweepy
from tweepy import OAuthHandler
import json
print("awaisTwit")
consumer_key = '**************'
consumer_secret = '**************'
access_token = '**************'
access_secret = '**************'
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
lise = list()
for status in tweepy.Cursor(api.home_timeline).items(10):
data2= status.text.encode('utf-8')
print(data2)
lise.append(data2)
for i in lise:
print(i.decode('utf-8'))
【问题讨论】:
标签: python-3.x twitter encoding utf-8