0

I used pyTelegramBotAPI (Telebot)

on getUpdates Telegram returns cyrillic name of sender "Шукур" as "first_name": "\u0428\u0443\u043a\u0443\u0440"

I have some code for telegram bot which answers with JSON string

    import bot_config
    import telebot 
    import json
    import jsonpickle
    bot = telebot.TeleBot(bot_config.token)
    @bot.message_handler( content_types=["text", "sticker","document","voice","video_note", "pinned_message", "photo", "audio"])
    def repeat_all_messages(message): 
    
        print('-----------START------------')
        newmessage = jsonpickle.encode(message)
        parsed = json.loads(newmessage)
        new = json.dumps(parsed, indent=4, sort_keys=True)
        new = new.encode('latin1').decode('utf8')
        new = f"<pre>{new}</pre>"
      
        bot.send_message(message.chat.id, new, parse_mode="HTML")
    if __name__ == '__main__':
         bot.infinity_polling()

So, how can I get "first_name": "Шукур" instead of "first_name": "\u0428\u0443\u043a\u0443\u0440"

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
scrz
  • 71
  • 9
  • 2
    Does this answer your question? [Unicode values in strings are escaped when dumping to JSON in Python](https://stackoverflow.com/questions/10865180/unicode-values-in-strings-are-escaped-when-dumping-to-json-in-python) – snakecharmerb Oct 31 '20 at 08:29
  • Yes, it works, thank you! – scrz Oct 31 '20 at 08:31

0 Answers0