Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tkinter.TclError: character U+1f449 is above the range (U+0000-U+FFFF) allowed by Tcl

I am trying to show my twitter timeline on Tkinter window using tweepy. This is the code

import tweepy
import tkinter

consumer_key = 'xxxxxxxxxxxxxx'
consumer_sec ='xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
acc_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
acc_token_sec = 'xxxxxxxxxxxxxxxxxxxxxx'
auth = tweepy.OAuthHandler(consumer_key,consumer_sec)
auth.set_access_token(acc_token,acc_token_sec)

api = tweepy.API(auth)

tweets = api.home_timeline()

tkwindow = tkinter.Tk()

for tweet in tweets:
    i = 1
    label = tkinter.Label(tkwindow, text=tweet.author.name + " " + str(tweet.created_at) + "\n" + str(tweet.text))
    if i == 5:
        break
tkwindow.mainloop()

But I am having following error

_tkinter.TclError: character U+1f449 is above the range (U+0000-U+FFFF) allowed by Tcl

I understand that tkinter can't show some special icons which appear in real tweets, But actually, I don't want to show those, I just want to show simple text of the tweet,

So How I can avoid this error and show only text of the tweets

like image 400
beginner Avatar asked Sep 12 '17 10:09

beginner


1 Answers

The easiest way to do this would be to strip out the extra characters. This could be done with the following code at the start of the for loop:

char_list = [tweet[j] for j in range(len(tweet)) if ord(tweet[j]) in range(65536)]
tweet=''
for j in char_list:
    tweet=tweet+j
like image 88
Temsia Carrolla Avatar answered Nov 11 '22 01:11

Temsia Carrolla