H
H
hey_umbrella2021-07-02 22:22:54
Python
hey_umbrella, 2021-07-02 22:22:54

Why does the sqlite error occur?

@bot.message_handler(content_types=['document'])
def handle_docs_photo(message):
    try:
        user_id = message.from_user.id
        username = message.from_user.username

        file_info = bot.get_file(message.document.file_id)
        downloaded_file = bot.download_file(file_info.file_path)
 
        src = 'images' + message.document.file_name;
        with open(f"images/{src}", 'wb') as new_file:
            new_file.write(downloaded_file)

        con = sqlite3.connect("database.db")
        cursor = con.cursor()
        cursor.execute(f"ALTER TABLE users ADD COLUMN {src} integer")
        cursor.execute(f'UPDATE users SET {src} = "images/{src}" WHERE telegram_id = "{user_id}"')
        con.commit()
        bot.send_message(message.chat.id, f"<b>Ваши обои приняты!Спасибо.</b>\n", parse_mode='html')
        img = open(f"images/{src}", 'rb')
        bot.send_message(admin_chat, f'User added new wallpaper!\n\ninfo: @{username} / {user_id} file name - {src}')
        bot.send_photo(admin_chat, img)
    except Exception as e:
        print(str(e))
        pass


What is the error, I searched for a long time and did not understand. near ".": syntax error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2021-07-02
@HemulGM

src = 'images' + message.document.file_name;

cursor.execute(f"ALTER TABLE users ADD COLUMN {src} integer")

Do you know what ALTER TABLE is?
Not clear hint?
And so:
src = 'images' + message.document.file_name;

src - imagesBOOBS.jpg
cursor.execute(f"ALTER TABLE users ADD COLUMN imagesBOOBS.jpg integer") <- Do you need such a column?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question