RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-573862

LeavingDeadGirl's questions

Martin Hope
LeavingDeadGirl
Asked: 2023-11-25 01:43:55 +0000 UTC

对 Telegram API 的请求失败。错误代码:400。说明:错误请求:无法解析回复键盘标记 JSON 对象

  • 4
import telebot
from telebot import types
import os

API_TOKEN = ''
admin_id = 
channel_id = 
bot = telebot.TeleBot(API_TOKEN)
p_inform = ''
v_inform = ''

def start_kb():
    kb_start = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True, row_width=5)
    btn1 = types.KeyboardButton("Послать фото")
    btn2 = types.KeyboardButton("Послать видео")
    kb_start.add(btn1, btn2)
    return kb_start

def wait_kb():
    kb_start = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True, row_width=5)
    btn1 = types.KeyboardButton("/start")
    kb_start.add(btn1)
    return kb_start

def a_d_kb():
    kb = types.ReplyKeyboardMarkup()
    a = types.KeyboardButton('Одобрить')
    d = types.KeyboardButton('Проклясть')
    kb.add(a,d)
    return kb

def terminate(cur):
    f=open('logs.txt','r').readlines()
    for i in f:
        if i == cur:
            f.pop(i)
    with open('logs.txt','w') as F:
        F.writelines(f)
    return 'Успешно'

def first():
    with open('logs.txt', 'r', encoding='utf-8') as f:
        return f.readline()
current_file, current_mess_author, current_mess_info, current_mess_name = '', '', '', ''
    
@bot.message_handler(commands=['start'])
def start(mes):
    if mes.chat.id != admin_id:
        bot.send_message(mes.chat.id, text='Приветствую тебя! Друг)', reply_markup=start_kb())
    else:
        kb = types.ReplyKeyboardMarkup()
        a = types.KeyboardButton('Поработать')
        kb.add(a)
        bot.send_message(mes.chat.id, text='ПРивет, ПАпОЧКа', reply_markup=kb)


                
    
def log(content, id, info):
    with open('logs.txt', 'a', encoding='utf-8') as file:
        file.write('\n'+ content + '|' + info + '|@' + id)

@bot.message_handler(content_types=['text'])
def text(mes):
    if mes.text == 'Послать фото':
        bot.send_message(mes.chat.id, text=f'Подпиши фото')
        bot.register_next_step_handler(mes, p_info)

    if mes.text == 'Послать видео':
        bot.send_message(mes.chat.id, text=f'Подпиши видео')
        bot.register_next_step_handler(mes, v_info)

    if mes.text == "Поработать":
        if os.path.getsize(r"C:\Users\temai\test2\logs.txt") == 0:
            bot.send_message(admin_id, text='Новых публикаций нет', reply_markup=[wait_kb])
        else:
            global current_file, current_mess_author, current_mess_info, current_mess_name
            current_file = first()
            current_mess_name = str(current_file.split('|')[0])
            current_mess_info = str(current_file.split('|')[1])
            current_mess_author = str(current_file.split('|')[2])
            if current_mess_name[0] == 'p':
                photo = open(r"C:\Users\temai\test2\images" + f"\{current_mess_name}", 'rb')
                bot.send_photo(admin_id, photo, caption=f'текст к фото:{current_mess_info}, создатель: {current_mess_author}', reply_markup=a_d_kb)
            if current_mess_name[0] == 'v':
                video = open(r"C:\Users\temai\test2\video" + f"\{current_mess_name}", 'rb')
                bot.send_video(admin_id, video, caption=f'текст к видео:{current_mess_info}, создатель: {current_mess_author}', reply_markup=a_d_kb) 

    if mes.text == 'Одобрить':
        if current_file[0] == 'p':
            photo = open(r"C:\Users\temai\test2\images" + f"\{current_mess_name}", 'rb')
            bot.send_photo(channel_id, photo, caption=f'{current_mess_info}\nCоздатель: {current_mess_author}')
            os.remove(r"C:\Users\temai\test2\images" + f"\{current_mess_name}")
            terminate(current_file)
        if current_file[0] == 'v':
            video = open(r"C:\Users\temai\test2\video" + f"\{current_mess_name}", 'rb')
            bot.send_video(channel_id, video, caption=f'{current_mess_info}\nCоздатель: {current_mess_author}')
            os.remove(r"C:\Users\temai\test2\video" + f"\{current_mess_name}")
            terminate(current_file)
    if mes.text == 'Проклясть':
        os.remove(r"C:\Users\temai\test2\images" + f"\{current_mess_name}")
        terminate(current_file)


def p_info(mes):
    global p_inform
    p_inform = mes.text
    bot.send_message(mes.chat.id, 'Пришли свое фото')
    bot.register_next_step_handler(mes, reg_photo)

def v_info(mes):
    global v_inform
    v_inform = mes.text
    bot.send_message(mes.chat.id, text='Пришли свое видео')
    bot.register_next_step_handler(mes, reg_video)

@bot.message_handler(content_types=['photo'])
def reg_photo(mes):
    file_info = bot.get_file(mes.photo[len(mes.photo) - 1].file_id)
    downloaded_file = bot.download_file(file_info.file_path)
    src = r"C:\Users\temai\test2\images\photo_" + mes.photo[1].file_id
    with open(src, 'wb') as new_file:
        new_file.write(downloaded_file)
    log('photo_'+mes.photo[1].file_id, mes.chat.username, p_inform)
    bot.send_message(mes.chat.id, text='Ваше фото в очереди на одобрение',reply_markup=start_kb())



    

@bot.message_handler(content_types=['video'])
def reg_video(mes):
    file_info = bot.get_file(mes.video.file_id)
    downloaded_file = bot.download_file(file_info.file_path)
    src =  r"C:\Users\temai\test2\video\vid_" + mes.video.file_id
    with open(src, 'wb') as new_file:
        new_file.write(downloaded_file)
    log('vid_'+ mes.video.file_id, mes.chat.username, v_inform)
    bot.send_message(mes.chat.id, text='Ваше видео в очереди на одобрение',reply_markup=start_kb())


bot.infinity_polling()

错误:

2023-11-24 20:38:53,130 (__init__.py:1083 MainThread) ERROR - TeleBot: "Threaded polling exception: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: can't parse reply keyboard markup JSON object"
2023-11-24 20:38:53,135 (__init__.py:1085 MainThread) ERROR - TeleBot: "Exception traceback:
Traceback (most recent call last):
  File "c:\Users\temai\test2\env\Lib\site-packages\telebot\__init__.py", line 1074, in __threaded_polling      
    self.worker_pool.raise_exceptions()
  File "c:\Users\temai\test2\env\Lib\site-packages\telebot\util.py", line 147, in raise_exceptions
    raise self.exception_info
  File "c:\Users\temai\test2\env\Lib\site-packages\telebot\util.py", line 90, in run
    task(*args, **kwargs)
  File "c:\Users\temai\test2\env\Lib\site-packages\telebot\__init__.py", line 6801, in _run_middlewares_and_handler
    result = handler['function'](message)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\temai\test2\main.py", line 75, in text
    bot.send_message(admin_id, text='Новых публикаций нет', reply_markup=[wait_kb])
  File "c:\Users\temai\test2\env\Lib\site-packages\telebot\__init__.py", line 1549, in send_message
    apihelper.send_message(
  File "c:\Users\temai\test2\env\Lib\site-packages\telebot\apihelper.py", line 264, in send_message
    return _make_request(token, method_url, params=payload, method='post')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\temai\test2\env\Lib\site-packages\telebot\apihelper.py", line 162, in _make_request
    json_result = _check_result(method_name, result)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\temai\test2\env\Lib\site-packages\telebot\apihelper.py", line 189, in _check_result
    raise ApiTelegramException(method_name, result, result_json)
telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: can't parse reply keyboard markup JSON object
"

大家好,我正在创建一个机器人,看起来快完成了,但是这里有一些疯狂的事情,请帮助我,告诉我可能导致错误的原因是什么?

telebot
  • 1 个回答
  • 33 Views
Martin Hope
LeavingDeadGirl
Asked: 2023-11-19 03:33:04 +0000 UTC

保存用户通过远程机器人键盘输入的数据

  • 5

我的机器人向用户发送一张图片和两个按钮,用户单击其中一个。我不知道如何记住用户的选择并将其与所选图片的名称一起写入数据库?

机器人算法:发送一张照片 -> 用户单击其中一个按钮(照片评级) -> 记录照片的评级和姓名

python
  • 1 个回答
  • 47 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5