Вот мой код:
import logging
from typing import Text
from aiogram import Bot, Dispatcher, executor, types
from requests.api import get
import config
import requests
import json
from aiogram.dispatcher.filters import Text
def get_bitcoin_price() -> int:
# Делаем запрос на получение цены биткоина
response = requests.get('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd').text
bitcoinjson = json.loads(response)
return int(bitcoinjson["bitcoin"]["usd"])
# Объект бота
bot = Bot(config.token)
# Диспетчер для бота
dp = Dispatcher(bot)
# Включаем логирование, чтобы не пропустить важные сообщения
logging.basicConfig(level=logging.INFO)
# Хэндлер на команду /price
@dp.message_handler(commands=["price"])
async def priceb(message: types.Message):
await message.answer(f"Цена биткоина = {get_bitcoin_price()}")
@dp.message_handler(commands=["alert"])
async def alarm(message: types.Message):
mean = int(message.text[6:])
n = False
while n == False:
if mean < get_bitcoin_price():
await message.answer(f"Цена биткоина пересекла вашу отметку {mean}")
n = True
if __name__ == "__main__":
# Запуск бота
executor.start_polling(dp, skip_updates=True)
а вот ошибка, возникающая после вызова команды /alert
ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-12' coro=<Dispatcher._process_polling_updates() done, defined at C:\Users\Vladimir\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\dispatcher.py:409> exception=JSONDecodeError('Expecting value: line 1 column 1 (char 0)')>
Traceback (most recent call last):
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 417, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 238, in process_updates
return await asyncio.gather(*tasks)
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 259, in process_update
return await self.message_handlers.notify(update.message)
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "c:\Users\Vladimir\Desktop\telegrambitcoinbot\bot.py", line 36, in alarm
if mean < get_bitcoin_price():
File "c:\Users\Vladimir\Desktop\telegrambitcoinbot\bot.py", line 13, in get_bitcoin_price
bitcoinjson = json.loads(response)
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Vladimir\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)