3

I'm trying to output emoji in Telegram automatically using python library pyautogui but however i found it impossible to just typewrite it. I searched for libraries to help me solve my problem and i found pyemojify and emoji but in both cases i faced

UnicodeEncodeError: 'charmap' codec can't encode characters: character maps to <undefined>

and the code is:

from pyemojify import emojify
print(emojify("Life is short :smile: , use :sparkles: Python :sparkles:"))

and this:

import emoji
print(emoji.emojize('Python is :thumbs_up_sign:'))

i searched here a lot but none of the answers finally worked for me. Now i have two questions: is there any way to output an emoji in Telegram using python pyautogui or even using java Robot class? and the second question is how i should fix UnicodeEncodeError in my code? Thanks in advance :)

szamani20
  • 650
  • 9
  • 26
  • The full traceback would be useful to find out exactly where the error is coming from. – Mark Ransom Nov 23 '15 at 19:15
  • And if it's coming from the `print`, it means that your `stdout` is not set up to support the full Unicode character set. Try printing `sys.stdout.encoding`. – Mark Ransom Nov 23 '15 at 19:17
  • It outputs `windows-1252` how should i manipulate `stdout` to support the full Unicode character set? I'm running python 3.4 on my x64 windows 8.1 machine. I've already seen [here](https://stackoverflow.com/questions/4374455/how-to-set-sys-stdout-encoding-in-python-3) but it didn't work at all. @MarkRansom – szamani20 Nov 24 '15 at 08:25
  • So i changed all of the encoding options in my IDE settings (Pycharm) to UTF-8 and then the output of `print(emoji.emojize('Python is :thumbs_up_sign:'))` is `Python is �` and i still face error for `print(emojify("Life is short :smile: , use :sparkles: Python :sparkles:"))` the error for this is `UnicodeEncodeError: 'utf-8' codec can't encode character '\ud83d' in position 14: surrogates not allowed ` printing normally like `print("\uD83D\uDE0D")` also give me the exact same error. – szamani20 Nov 24 '15 at 09:41
  • Not sure how to help you at this point, I'm not familiar with Pycharm or the libraries you're using. But at least there's enough information for someone else to figure it out - you should edit the question. I will say it sounds like a mistake for `emojify` to be producing surrogates instead of a single codepoint. – Mark Ransom Nov 24 '15 at 12:24

1 Answers1

-2
from selenium import webdriver

b = webdriver.Firefox()
b.get('https://web.telegram.org')
....
....
b.find_elements_by_class_name('composer_rich_textarea')[0].send_keys('\U0001F422')
print('\U0001F422'.encode('utf-8'))
Smart Manoj
  • 5,230
  • 4
  • 34
  • 59