A
A
Alexander2018-06-17 18:31:26
Python
Alexander, 2018-06-17 18:31:26

How to transfer the Russian language to the chatbot keyboard?

Good afternoon, I started to deal with the keyboard for chat bots VK, here is my code:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
import json


def write_message(user_id, msg, keyboard=False):
    if keyboard == False:
        vk_session.method('messages.send', {'user_id': user_id, 'message': msg})
    else:
        vk_session.method('messages.send', {'user_id': user_id, 'message': msg, 'keyboard': str(json.dumps(keyboard))})


KEYBOARD_STEP_1 = {
    'one_time': False,
    'buttons': 
}

write_message(user_id, message, KEYBOARD_STEP_1)

At the output I get this:
5b267e6b1d397195929231.png
How to correctly transfer the string so that Russian characters are displayed correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-06-20
@AlexMine

Hello Alex Mine !
Faced the same problem in PHP.
The solution turned out to be simple, I used the JSON_UNESCAPED_UNICODE parameter when encoded.
Try something similar in python.
5b2aaa88c2152389115478.png

M
Merzavets, 2018-07-30
@Merzavets

Just add ensure_ascii=False:

[...] json.dumps(KEYBOARD_STEP_1, ensure_ascii=False)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question