H
H
hey_umbrella2021-07-07 01:01:36
Python
hey_umbrella, 2021-07-07 01:01:36

What is sqlite python error?

try:
            img2 = open(f'{maxmark[2][0]}', 'rb')
            mime = magic.Magic(mime=True)
            filename = mime.from_file(maxmark[2])
            if filename.find('image') != -1:
                con = sqlite3.connect("database.db")
                cursor = con.cursor()
                cursor.execute(f'SELECT username FROM PHOTOSLOTS WHERE slots = "{maxmark[2]}"')
                username = cursor.fetchone()
                con.commit()
                cursor.execute(f'SELECT namerank FROM users WHERE username = "{username[0]}"')
                namerank = cursor.fetchone()
                con.commit()
                dataCopy = cursor.execute(f'SELECT count(slots) FROM PHOTOSLOTS WHERE username = "{username[0]}"')
                values = dataCopy.fetchone()
                con.commit()
                cursor.execute(f'SELECT star FROM stars WHERE photo = "{maxmark[2]}" ') 
                mark = cursor.fetchone()
                if namerank is not None:
                    bot.send_message(message.chat.id, f'┃➣ Автор - @{username[0]} \n'
                    f'┃➣ Количество обоев - {values[0]}\n'
                    f'┃➣ Уровень - {namerank[0]}\n', reply_markup=key_com)
                else:
                    bot.send_message(message.chat.id, f'┃➣ Автор - @{username[0]} \n'
                    f'┃➣ Количество обоев - {values[0]}\n'
                    f'┃➣ Уровень - {namerank}\n', reply_markup=key_com)
                    bot.send_photo(message.chat.id, img2)
                    bot.send_message(message.chat.id, maxmark[0], reply_markup=marku)
            elif filename.find('video') != -1:
                con = sqlite3.connect("database.db")
                cursor = con.cursor()
                cursor.execute(f'SELECT username FROM PHOTOSLOTS WHERE slots = "{maxmark[2]}"')
                username = cursor.fetchone()
                con.commit()
                cursor.execute(f'SELECT namerank FROM users WHERE username = "{username[0]}"')
                namerank = cursor.fetchone()
                con.commit()
                dataCopy = cursor.execute(f'SELECT count(slots) FROM PHOTOSLOTS WHERE username = "{username[0]}"')
                values = dataCopy.fetchone()
                con.commit()
                cursor.execute(f'SELECT star FROM stars WHERE photo = "{maxmark[2]}" ') 
                mark = cursor.fetchone()
                if namerank is not None:
                    bot.send_message(message.chat.id, f'┃➣ Автор - @{username[0]} \n'
                    f'┃➣ Количество обоев - {values[0]}\n'
                    f'┃➣ Уровень - {namerank[0]}\n', reply_markup=key_com)
                else:
                    bot.send_message(message.chat.id, f'┃➣ Автор - @{username[0]} \n'
                    f'┃➣ Количество обоев - {values[0]}\n'
                    f'┃➣ Уровень - {namerank}\n', reply_markup=key_com)
                    bot.send_video(message.chat.id, img2)
                    bot.send_message(message.chat.id, maxmark[2], reply_markup=marku)
        except Exception as e:
            print(e)
            bot.send_message(message.chat.id, f'<b>『ТОП 3』 - </b>{maxmark[2][0]}', reply_markup=markup3, parse_mode='html')


Error expected str, bytes or os.PathLike object, not tuple

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-07-07
@hey_umbrella

img2 = open(f'{maxmark[2][0]}', 'rb')
            mime = magic.Magic(mime=True)
            filename = mime.from_file(maxmark[2])

Line one implies that the filename is maxmark[2][0]. Then maxmark[2] is probably a collection, tuple, list, or dictionary, because I don't think you're opening a file with a single character name. By the way, why f'{maxmark[2][0]}'?
But in line three, judging by the name of the method, you need to pass a string with the path to the file file - and maxmark[2] is passed there, which we have already defined as a possible tuple.
This matches the error text.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question