Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14155

ModuleNotFoundError: No module named 'aiogram'

$
0
0

I work in VS Code and I was asked to change the telegram bot script from python-telegram-bot library to aiogram. I've installed that via 'pip install aiogram' and still getting errors like ModuleNotFoundError: No module named 'aiogram' and I don't know what to do.

import loggingfrom aiogram import Bot, Dispatcher, typesfrom aiogram.types import ParseModefrom aiogram.utils import executorimport requestsTELEGRAM_BOT_TOKEN = 'XXXXXXXX'COINGECKO_API_KEY = 'XXXXXXXX'logging.basicConfig(level=logging.INFO)bot = Bot(token=TELEGRAM_BOT_TOKEN)dp = Dispatcher(bot)# Function to get token price from CoinGeckodef get_token_price(token_id):    url = f'https://api.coingecko.com/api/v3/simple/price?ids={token_id}&vs_currencies=usd'    headers = {'Authorization': f'Bearer {COINGECKO_API_KEY}'}    response = requests.get(url, headers=headers)    data = response.json()    if 'error' in data:        logging.error(f'Error from CoinGecko API: {data["error"]}')        return None    try:        price = data[token_id]['usd']        return price    except KeyError:        logging.error(f'KeyError: Could not find price for token with ID {token_id}')        return None# Command handlers@dp.message_handler(commands=['btc'])async def get_btc(message: types.Message):    price = get_token_price('bitcoin')    if price is not None:        await message.reply(f'Ціна Bitcoin: {price} USD')    else:        await message.reply('Невдалосяотриматицінудля Bitcoin')@dp.message_handler(commands=['eth'])async def get_eth(message: types.Message):    price = get_token_price('ethereum')    if price is not None:        await message.reply(f'Ціна Ethereum: {price} USD')    else:        await message.reply('Невдалосяотриматицінудля Ethereum')@dp.message_handler(commands=['sfund'])async def get_sfund(message: types.Message):    price = get_token_price('seedify-fund')    if price is not None:        await message.reply(f'Ціна Seedify: {price} USD')    else:        await message.reply('Невдалосяотриматицінудля Seedify Fund')@dp.message_handler(commands=['cgpt'])async def get_cgpt(message: types.Message):    price = get_token_price('chaingpt')    if price is not None:        await message.reply(f'Ціна ChainGPT: {price} USD')    else:        await message.reply('Невдалосяотриматицінудля ChainGPT')@dp.message_handler(commands=['bnb'])async def get_bnb(message: types.Message):    price = get_token_price('binancecoin')    if price is not None:        await message.reply(f'Ціна BNB: {price} USD')    else:        await message.reply('Невдалосяотриматицінудля Binance Coin (BNB)')if __name__ == '__main__':    from aiogram import executor    executor.start_polling(dp, skip_updates=True)

Tried to create a new project (sometimes helps) and still same error


Viewing all articles
Browse latest Browse all 14155

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>