D
D
darknos232021-03-18 05:04:29
Python
darknos23, 2021-03-18 05:04:29

Error: One of the parameters specified was missing or invalid: keyboard contains incorrect JSON?

Hello, I'm trying to send a keyboard via vk_api, I constantly get an error about the wrong format.

import vk_api,json,random
import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
from vk_api.keyboard import VkKeyboard, VkKeyboardColor
token="123456789"  

vk = vk_api.VkApi(token = token)
longpoll = VkLongPoll(vk)


keyboard = VkKeyboard(one_time=True)
keyboard.add_button('Кнопка1', color=VkKeyboardColor.SECONDARY)
keyboard.add_button('Кнопка2', color=VkKeyboardColor.POSITIVE)
keyboard.add_button('Кнопка3', color=VkKeyboardColor.POSITIVE)
keyboard.add_button('Кнопка4', color=VkKeyboardColor.POSITIVE)




def sender(id,text):
  vk.method("messages.send",{"chat_id": id, "message" : text, "random_id": 0, "keyboard":keyboard.get_keyboard})

while True:
  
  for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW:
      if event.to_me:
        if event.from_chat:
          
          
          ms1 = event.text.lower()
          id = event.chat_id
          if ms1 == "1111":
            sender(id,"11111")

Error itself: vk_api.exceptions.ApiError: [100] One of the parameters specified was missing or invalid: keyboard contains incorrect JSON
thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-03-18
@SoreMix

get_keyboard - function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question