P
P
pozner882021-09-25 12:26:03
Python
pozner88, 2021-09-25 12:26:03

How to send a function argument so that it would be accepted by pycharm when working with sql?

I create a tg bot with the aiorgam library, I need to create a database, for this I turned to the SQL library.
In order not to clutter up the main code, I made a separate file with SQL access functions, and other necessary things. When calling the write function to the database gives an error

TypeError: db_table_val() missing 1 required positional argument: 'date'

The main code itself
import sqlite3 as sq
from aiogram import Bot, Dispatcher, executor, types
from table_sql import  create, db_table_val, add_data

bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot, storage=storage)

con = sq.connect('databased.db')
cur = con.cursor()
con.execute(f"""CREATE TABLE IF NOT EXISTS users (user_id, username)""")
con.commit()
@dp.message_handler(commands=['start'])
async def start_bot(message: types.Message):
    await bot.send_message(message.from_user.id, text='the bot started' )
    await bot.send_message(chat_id=admin, text='the bot started ' 
                                               +"\n @"+str(message.from_user.username ))
    db_table_val(message.from_user.id, message.from_user.username, message.date)

And the function code
import sqlite3 as sq
import aiogram

con = sq.connect('databased.db')
cur = con.cursor()
sq.connect('databased.db') as con:
con.execute(f"""CREATE TABLE IF NOT EXISTS {message.from_user.username} (user_id, username, date)""")
con.commit()
def db_table_val(message, user_id, username, date:str ):
        cur.execute(f'INSERT INTO {message.from_user.username} (user_id, username, date) VALUES (?, ?, ?)',
                       (user_id, username, date))

        con.commit()

In this case, if you do not write the function in a separate file, everything works fine.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kirillinyakin, 2021-09-25
@pozner88

You have to pass 4 arguments to the db_table_val function, and you pass only 3 to the main function, which is what the error says

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question