2013-10-09 2 views
0

나는 Twittter API와 파이썬잡아 트윗 UnicodeEncodeError

내가 로그인과 결과 사전을 얻을 수의 OAuth를 사용

를 사용하여 트윗의 텍스트를 잡기 위해 노력하고 발생 0] 사전입니다 : 등

{u'contributors': None, u'truncated': False, u'text': u'RT @Kagame_quotes: "We, the people of #Rwanda, our country has its own problems that we can\u2019t attribute to others, we need to find solution\u2026', u'in_reply_to_status_id': None, u'id': 387905246028394496L, u'favorite_count': 0, u'source': u'<a href="http://twitter.com" rel="nofollow">Twitter Web Client</a>', u'retweeted': False, u'coordinates': None, ...

나는 단지 u'text' 키에 대한 값을 잡아하려는 (즉 트윗을 얻을) 0

for item in list: 
    print item[u'text'] 

을하지만 그것은 나에게 오류 제공합니다 : 그래서 쓰기

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' 
in position 91: ordinal not in range(128) 

가 어떻게이 u'text' 키에 대한 값을 잡을 수 있습니까? 트릭을 할해야

for item in list: 
    print item[u'text'].encode('utf-8') 

:

+3

변수 이름으로'list'를 사용하지 마십시오 . –

답변

1

당신은 UTF-8 인코딩을 지정해야합니다.

0

텍스트에 오류가 없습니다. 그것은 당신이 당신의 consolle에 인쇄 할 수없는 유니 코드 문자들을 담고 있습니다. 특히

(이 http://www.utf8-chartable.de/unicode-utf8-table.pl 체크 아웃) :

  • U + 2019 RIGHT 단일 인용 MARK
  • U + 2026 생략 부호