Ascii' codec can't encode character u'\u2019' in position 1: ordinal not in range(128)


#1

Hi, got this strange error in “Understanding Twitter Results II”:

@omgleil find Harlem bad tweets about Nicki and get him out of here!
Barbies reporting their own kind… WOW.
THEY GOT OUR FAVORITE ■■■■■ WOW https://t.co/asBB1znonc
@TheShawnyboy HAPPY BIRTHDAY ■■■■■, WHEN I COME TO MEMPHIS WE GETTING LIT?
@IGoByAlice WHAT DID HE DONJEJKWWISIA
Traceback (most recent call last):
File “CelebrityMatch.py”, line 20, in
print status.text
UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\u2019’ in position 1: ordinal not in range(128)


Code:
import sys
import operator
import requests
import json
import twitter
from watson_developer_cloud import PersonalityInsightsV2 as PersonalityInsights

twitter_consumer_key =
twitter_consumer_secret =
twitter_access_token =
twitter_access_secret =

twitter_api = twitter.Api(consumer_key=twitter_consumer_key, consumer_secret=twitter_consumer_secret, access_token_key=twitter_access_token, access_token_secret=twitter_access_secret)

handle = "@badgalriri"
statuses = twitter_api.GetUserTimeline(screen_name=handle, count=200, include_rts=False)

for status in statuses:
print status.text


#2

Try this.

for status in statuses:
print status.text.encode(“utf-8”)

python2.7 unicode handling :frowning:


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.