首页 > 解决方案 > 使用 tableq sqlite 时出错。该怎么办?

问题描述

我有这样的代码:

def pay (message):
    token = config.CONFIG ['qiwi']
    phone = config.CONFIG ['phone']
    db = sqlite3.connect ('users.db')
    cursor = db.cursor ()

    cursor.execute ("" "CREATE TABLE IF NOT EXISTS users (
        user_id TEXT,
        qrule TEXT,
        cash INTEGER,
        usersinbot INTEGER,
        pay TEXT,
        pay_money INTEGER
        
    ) "" ")
    price = message.text
    api = QApi (token = token, phone = phone)
    if not price.isdigit ():
        client.send_message (message.chat.id, 'Please enter a valid value')
        main (message)
        return
    price = int (price)
    
    comment = api.bill (price)
    cursor.execute (f "UPDATE users SET pay = {str (comment)} WHERE user_id = '{message.chat.id}'")
    db.commit ()
    cursor.execute (f "UPDATE users SET pay_money = {price} WHERE user_id = '{message.chat.id}'")
    db.commit ()
    
    markup_inline = types.InlineKeyboardMarkup ()

    item_pay = types.InlineKeyboardButton (text = 'Pay', url = 'link_to_pay')
    item_check = types.InlineKeyboardButton (text = 'Check payment', callback_data = 'check')
    item_back = types.InlineKeyboardButton (text = 'Back', callback_data = 'bck')
    markup_inline.add (item_pay)
    markup_inline.add (item_check)
    markup_inline.add (item_back)
    client.send_message (message.chat.id, f'To proceed to payment, click the pay button and leave the code in the comments for the payment: {comment}. If you do not leave the code, the bot will not accept the payment. In the amount for payment, indicate the same number what you posted earlier. ', reply_markup = markup_inline)

注释变量存储一个用于使用 kiwi api 的令牌。示例令牌 - 901ecc36-82fd-46ba-8792-9f40abe01319

当我执行支付功能时,我得到了错误:

Traceback (most recent call last):
  File "c:/Users/Дом/Desktop/Py/PY/tg_bot_frilance/main.py", line 369, in <module>
    client.polling(none_stop=True, interval=0)
  File "C:\Users\Дом\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\__init__.py", line 619, in polling
    self.__threaded_polling(none_stop, interval, timeout, long_polling_timeout, allowed_updates)
  File "C:\Users\Дом\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\__init__.py", line 678, in __threaded_polling
    raise e
  File "C:\Users\Дом\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\__init__.py", line 641, in __threaded_polling
    self.worker_pool.raise_exceptions()
  File "C:\Users\Дом\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\util.py", line 130, in raise_exceptions
    raise self.exception_info
  File "C:\Users\Дом\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\util.py", line 82, in run
    task(*args, **kwargs)
  File "c:/Users/Дом/Desktop/Py/PY/tg_bot_frilance/main.py", line 99, in pay
    cursor.execute(f"UPDATE users SET pay = {str(comment)} WHERE user_id = '{message.chat.id}'")
sqlite3.OperationalError: unrecognized token: "472f"

为什么我会得到它,我该如何解决?

标签: pythonpython-3.xsqlite

解决方案


推荐阅读