Telegram возвратил неверный запрос HTTP 400 [pyTelegramBotAPI] - PullRequest
0 голосов
/ 21 января 2019

Я добавил новый метод формы pyTelegramBotAPI ' edit_message_caption (caption = captionEv) ' для моего бота для редактирования подписи к фотографии ниже, но что-то не работает верно. Я не нашел больше информации об использовании метода редактирования для изменения заголовка в библиотеке Telebot. Итак, мне нужна помощь в реализации метода. Telegram верни мне Плохой запрос HTTP 400.

#!/usr/bin/env python
import psycopg2 as db
import random
import telebot 
import sys
from telebot import *
from telebot.types import Message

TOKEN = '77*****************************'

bot = telebot.TeleBot(TOKEN)

#USERS = set()

@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
    if call.message or call.inline_message_id:  

        conEdit = None  
        try:
            conEdit  = db.connect( database = "db",
            user = "mer", 
            password = "pass", 
            host = "host", 
            port = "5432")
            cursor = conEdit.cursor()
            cursor.execute("SELECT * FROM events WHERE id = \'"+call.data+"\';")
            rows = cursor.fetchall()
            for row in rows:
                if row == None:
                    print('Sorry, but rafs not added')

                else:
                    title = row[1]
                    speakerAbout = row[6]
                    organizerAbout = row[8] 
                    link = row[10]

                    captionEv = ( title + 
                    "\n===================\n" +
                    ":hash: ПРО СПІКЕРІВ: \n" + speakerAbout + 
                    "\n===================\n" +
                    ":hash: ПРО ОРГАНІЗАТОРІВ: \n" + organizerAbout + 
                    "\n===================\n" +
                    ":hash: Link: " + link + 
                    "\n===================\n")

                    bot.edit_message_caption(caption=captionEv)

            #con.close()

        except (Exception, db.DatabaseError) as error:
            print(error)

        if conEdit is not None:
            conEdit.close()

@bot.edited_message_handler(content_types=['text'])
@bot.message_handler(content_types=['text'])
def echo_digits(message: Message):
    markup = types.ReplyKeyboardMarkup()
    itembtnLAST = types.KeyboardButton('Last week')
    itembtnTHIS = types.KeyboardButton('This week')
    itembtnNEXT = types.KeyboardButton('Next week')
    itembtnJava = types.KeyboardButton('Java')
    itembtnC_plus_plus = types.KeyboardButton('C++')
    itembtnDesign = types.KeyboardButton('Design')
    itembtnMarketing = types.KeyboardButton('Marketing')
    itembtnC = types.KeyboardButton('C')
    itembtnPython = types.KeyboardButton('Python')
    itembtnJavaScript = types.KeyboardButton('JavaScript')
    itembtn_dotNET = types.KeyboardButton('.NET')
    itembtn_iOS_macOS= types.KeyboardButton('iOS/macOS')
    itembtnAndroid = types.KeyboardButton('Android')
    itembtnMeetups = types.KeyboardButton('Meetups')
    itembtnDeveloping = types.KeyboardButton('Developing')
    markup.row(itembtnLAST, itembtnTHIS, itembtnNEXT)
    markup.row(itembtnJava, itembtnC_plus_plus, itembtnC)
    markup.row(itembtnPython, itembtnJavaScript, itembtn_dotNET)
    markup.row(itembtnAndroid, itembtnDeveloping, itembtn_iOS_macOS)
    markup.row(itembtnMarketing, itembtnMeetups, itembtnDesign)

    category = 'null'
    week = 'null'
    command = 'null'

    if '/start' in message.text:
        bot.send_message(message.chat.id, "Eventor - the new way of finding professional events", reply_markup=markup)
        command = 'not null'
    if '/help' in message.text:
        bot.send_message(message.chat.id,'Ваші іструкції:\n===================\n Щоб знайти івент:\n===================\n- Виберіть категорію або тиждень;\n- Оберіть ваш івент із списку наданих;\n- Насолоджуйтесь!\n===================\nЗвяжіться з нами:\n *.*@yahoo.com\n===================\n', reply_markup=markup)
        command = 'not null'

    if 'Last week' in message.text:
        week = 'last'
        command = 'not null'
    if 'This week' in message.text:
        week = 'this'
        command = 'not null'
    if 'Next week' in message.text:
        week = 'next'
        command = 'not null'

    if 'Java' in message.text:
        category = 'java'
        command = 'not null'
    if 'C++' in message.text:
        category = 'c_plus_plus'
        command = 'not null'
    if 'Design' in message.text:
        category = 'design'
        command = 'not null'
    if 'Marketing' in message.text:
        category = 'marketing'
        command = 'not null'
    if 'C' in message.text:
        category = 'c'
        command = 'not null'
    if 'Python' in message.text:
        category = 'python'
        command = 'not null'
    if 'JavaScript' in message.text:
        category = 'javascript'
        command = 'not null'
    if '.NET' in message.text:
        category = 'dot_net'
        command = 'not null'
    if 'iOS/macOS' in message.text:
        category = 'ioa_macos'
        command = 'not null'
    if 'Android' in message.text:
        category = 'android'
        command = 'not null'
    if 'Meetups' in message.text:
        category = 'meetups'
        command = 'not null'
    if 'Developing' in message.text:
        category = 'developing'
        command = 'not null'

    if category == 'null' and week == 'null' and command == 'null':
        bot.send_message(message.chat.id, "Вибачте, але на даний момент цієї події немає")

    #USERS.add(message.from_user.id)
    con = None  
    try:
        con = db.connect( database = "f",
        user = "f", 
        password = "sd", 
        host = "sd", 
        port = "5432")
        cursor = con.cursor()
        cursor.execute("SELECT * FROM events WHERE category = \'"+category+"\' OR week = \'"+week+"\';")
        rows = cursor.fetchall()

        for row in rows:
            if row == None:
                print('Sorry, but rafs not added')

            else:
                id = row[0]
                title = row[1]
                whenStart = row[2]
                whereStart = row[3]
                description = row[4]
                speaker = row[5]
                organizer = row[7]
                image = row[11]
                caption = (title +
                "\n===================\n" +
                ":hash: КОЛИ:  " + whenStart +
                "\n===================\n" +
                ":hash: ДЕ:  " + whereStart +
                "\n===================\n" +
                ":hash: ОПИС:  " + description +
                "\n===================\n" +
                ":loudspeaker: " + speaker +
                "\n===================\n" +
                "ОРГАНІЗОВУЄ: " + organizer +
                "\n===================\n")              
                keyboard = types.InlineKeyboardMarkup()
                button_description = types.InlineKeyboardButton(text='Детальніше', callback_data=id)
                keyboard.add(button_description)
                bot.send_photo(message.chat.id, image, caption, reply_markup=keyboard)                                                      


        #con.close()                


    except (Exception, db.DatabaseError) as error:
        print(error)

    if con is not None:
        con.close()


@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
    if call.message or call.inline_message_id:  

        conEdit = None  
        try:
            conEdit  = db.connect( database = "f",
            user = "f", 
            password = "df", 
            host = "df", 
            port = "5432")
            cursor = conEdit.cursor()
            cursor.execute("SELECT * FROM events WHERE id = \'"+call.data+"\';")
            rows = cursor.fetchall()
            for row in rows:
                if row == None:
                    print('Sorry, but events not added')

                else:
                    title = row[1]
                    speakerAbout = row[6]
                    organizerAbout = row[8] 
                    link = row[10]

                    captionEv = ( title + 
                    "\n===================\n" +
                    ":hash: ПРО СПІКЕРІВ: \n" + speakerAbout + 
                    "\n===================\n" +
                    ":hash: ПРО ОРГАНІЗАТОРІВ: \n" + organizerAbout + 
                    "\n===================\n" +
                    ":hash: Link: " + link + 
                    "\n===================\n")

                    bot.edit_message_caption(caption=captionEv)

            #con.close()

        except (Exception, db.DatabaseError) as error:
            print(error)

        if conEdit is not None:
            conEdit.close()

bot.polling(timeout=60)
...