A
A
Alexey Mikhalev2020-07-20 18:46:27
Python
Alexey Mikhalev, 2020-07-20 18:46:27

How to fix can "only concatenate tuple (not "str") to tuple" error?

Good evening. I am writing a bot. The essence is simple, the user clicks on the desired button, and then the bot edits the message to the text that the code forms by pulling the text from several SQLite database cells. I am using the PyTelegramBotApi library. What caused the error and how to avoid it? Thanks in advance to everyone for your help.
Mistake:

File "bot.py", line 244, in callback_inline
    bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=product_name('bud1') + "\n" + "-----------------\n" + product_about('bud1') + "\n" + "\n"+"Цена: "+product_price('bud1'), parse_mode='html', reply_markup=markup)
TypeError: can only concatenate tuple (not "str") to tuple

Functions of calls to the database:
def product_name(id ):
    with sqlite3.connect('database.db') as connection:
        cursor = connection.cursor()
        cursor.execute("SELECT `name` FROM `catalog` WHERE `id` = ? ", (id,))
        result = cursor.fetchone()
        return result

def product_about(id ):
    with sqlite3.connect('database.db') as connection:
        cursor = connection.cursor()
        cursor.execute("SELECT `about` FROM `catalog` WHERE `id` = ? ", (id,))
        result = cursor.fetchone()
        return result
 
def product_price(id ):
    with sqlite3.connect('database.db') as connection:
        cursor = connection.cursor()
        cursor.execute("SELECT `price` FROM `catalog` WHERE `id` = ? ", (id,))
        result = cursor.fetchone()
        return result

Button output code:
if call.data == 'bud-1':

        markup = types.InlineKeyboardMarkup(row_width=1)
        item1 = types.InlineKeyboardButton("Назад", callback_data='bud')
        markup.add(item1)

        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=product_name('bud1') + "\n" + "-----------------\n" + product_about('bud1') + "\n" + "\n"+"Цена: "+product_price('bud1'), parse_mode='html', reply_markup=markup)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-07-20
@mikkhalev

TypeError: can only concatenate tuple (not "str") to tuple

Type error: You can only add tuple (not string) to tuple
You are adding tuple and string. Decision? Do not add different types, cast them to one through the corresponding functions int(), str(), list() etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question