python 3.x - python3 中使用 Tweepy 时出错:UnicodeEncodeError:'charmap'编解码器无法对位置 0-1 中的字符进行编码:字符映射到<un



我想使用lib: tweepy提取一些tweet。在打印数据时,它给出了错误UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1,然后我使用.decode('utf-8')给出了decode。但过了一段时间,为了人性化地阅读它,我想用.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')) 

通过转到Eclipse->Windows->首选项->常规->工作区->文本文件编码到utf8来解决问题。

最新更新