Ошибка при переходе на кнопку, функция не выполняется

Рейтинг: 0Ответов: 1Опубликовано: 22.05.2023
Task exception was never retrieved
future: <Task finished name='Task-85' coro=<Dispatcher._process_polling_updates() done, defined at C:\Users\rasul\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=TypeError("unsupported operand type(s) for /: 'str' and 'int'")>
Traceback (most recent call last):
  File "C:\Users\rasul\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 415, in _process_polling_updates
    for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
  File "C:\Users\rasul\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
    return await asyncio.gather(*tasks)
  File "C:\Users\rasul\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify       
    response = await handler_obj.handler(*args, **partial_data)
  File "C:\Users\rasul\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 283, in process_update
    return await self.callback_query_handlers.notify(update.callback_query)
  File "C:\Users\rasul\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "C:\Users\rasul\Desktop\sms active\handlers\user\callback.py", line 162, in handler_call
    text, markup = await RentNumber().buy_rent_menu(call.data.split(":")[1], call.data.split(":")[2], call.data.split(":")[3])
  File "C:\Users\rasul\Desktop\sms active\utils\rent.py", line 297, in buy_rent_menu
    <b>💳 Цена:</b> <i>{await self.rent_price(service, country, time)} RUB</i>
  File "C:\Users\rasul\Desktop\sms active\utils\rent.py", line 103, in rent_price
    price = price / 100 * 20 + price
TypeError: unsupported operand type(s) for /: 'str' and 'int'

Что надо тут поменять не понимаю до конца

if call.data.split(":")[0] == 'rent_time':
            text, markup = await RentNumber().buy_rent_menu(call.data.split(":")[1], call.data.split(":")[2], call.data.split(":")[3])
            await call.message.edit_caption(caption=text, reply_markup=markup)


<b>💳 Цена:</b> <i>{await self.rent_price(service, country, time)} RUB</i>
<b>🧿 Кол-во номеров:</b> <i>{await self.rent_quant(country, service, time)} шт</i>




   async def rent_price(self, service, country, time):
        price = await self.get_price(service, country, time)

        if price != 0:

            if time == 12:
                price = price / 100 * \
                    int(config.config("rent_percent_12h")) + price
            elif time == 24:
                price = price / 100 * \
                    int(config.config("rent_percent_24h")) + price
            elif time == 72:
                price = price / 100 * \
                    int(config.config("rent_percent_72h")) + price
            elif time == 168:
                price = price / 100 * \
                    int(config.config("rent_percent_168h")) + price
            elif time == 336:
                price = price / 100 * \
                int(config.config("rent_percent_336h")) + price
            else:
                price = price / 100 * 20 + price
        else:
            price = 0

        return round(price)

Ругается именно на эти строчки кода

Ответы

▲ 1Принят

У вас переменная "price" не является целочисленной переменной, а потому с ней нельзя производить расчеты...

Узнать тип переменной можно командой:

print(type(price))

Она выведет в терминале тип переменной.

Чтобы преобразовать переменную в целочисленный тип используйте преобразование:

price = int(price)