【问题标题】:Error in python3 using Tweepy : UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1: character maps to <undefined>python3 中使用 Tweepy 时出错:UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1: character maps to <undefined>
【发布时间】: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


    【解决方案1】:

    通过 Eclipse -> Windows -> Preferences -> General -> Workspace -> Text File Encoding to utf8 解决了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-18
      • 2017-05-10
      • 2020-08-05
      相关资源
      最近更新 更多