Помогите с телеграм ботом на python

Рейтинг: 0Ответов: 0Опубликовано: 22.01.2023

Хелп пж Заранее спасибо!

from aiogram import Bot, types, asyncio
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
import sqlite3 as sql
from aiogram.utils.exceptions import Throttled
from aiogram.dispatcher.filters import BoundFilter
import requests
from aiogram.types import ReplyKeyboardRemove, ReplyKeyboardMarkup, KeyboardButton, InlineKeyboardMarkup, InlineKeyboardButton
import random
from aiogram.dispatcher import FSMContext                            
from aiogram.dispatcher.filters import Command                     
from aiogram.contrib.fsm_storage.memory import MemoryStorage        
from aiogram.dispatcher.filters.state import StatesGroup, State 
from aiogram.contrib.fsm_storage.memory import MemoryStorage
import urllib.request
import json
from requests import get


from dadata import DadataAsync

oken = "5840330858:AAEbpiвлвлвлв7CcL2T-e6B15sB0" # токен бота тг



token = "018b4e1de10ed221c6cadнет3f66"
secret = "cd3ebfe280не дам 0227438cde54747dc" # получать на dadata
dadata = DadataAsync(token, secret)



bot = Bot(token=oken)
dp = Dispatcher(bot, storage=MemoryStorage())



class meinfo(StatesGroup):
    Q3 = State()
    Q2 = State()

@dp.message_handler(commands=['start'])
async def start(message):
    await message.answer('Привет, я помогу найти информацию о номере телефона/ip\n\nДля пробива по номеру введите /number\nДля пробива по IP введите /ip')

@dp.message_handler(content_types=['text'])
async def get_message(message):
    if message.text == "/number":           
        await message.answer("Введите номер телефона")
        await meinfo.Q3.set()
    if message.text == "/ip":             
        await message.answer("Введите IP адрес")
        await meinfo.Q2.set()



@dp.message_handler(state=meinfo.Q3)
async def answer_q3(message: types.Message, state: FSMContext):
    answer = message.text
    await state.update_data(answer3=answer)
    data = await state.get_data()                #
    answer3 = data.get("answer3")
    result = await dadata.clean("phone", answer3)
    cont = InlineKeyboardMarkup(row_width=2)
    wh = InlineKeyboardButton("✅ WhatsApp", url=f"""wa.me/{result["phone"]}""")
    ch = InlineKeyboardButton("✅ Канал прогера", url=f"https://t.me/rahimdark")
    cont.add(wh, ch)

    await bot.send_message(message.from_user.id, f"""📱 Телефон: {result["number"]}
🏬 Страна: {result["country"]}
🏠 Регион: {result["region"]}
🏭 Город: {result["city"]}
🕗 Часовой пояс: {result["timezone"]}
📶 Оператор: {result["provider"]}""", reply_markup=cont)
 
    await state.finish()

@dp.message_handler(state=meinfo.Q2)
async def answer_q2(message: types.Message, state: FSMContext):
    answer = message.text
    await state.update_data(answer2=answer)
    data = await state.get_data()                
    ip = data.get("answer2")
    url = f'https://ipapi.co/{ip}/json'
    info = requests.get(url).json()
    await message.reply(f'Город: {info["city"]}\nРегион: {info["region"]}\nСтрана: {info["country_name"]}\nВалюта: {info["currency"]}\nНаселение страны: {info["country_population"]}\nПровайдер: {info["org"]}') 
    print("info")
    await message.answer(message.text)
    await state.finish()



if __name__ == "__main__":
    executor.start_polling(dp, skip_updates=True)   

ошибка

Updates were skipped successfully.
Task exception was never retrieved
future: <Task finished name='Task-14' coro=<Dispatcher._process_polling_updates() done, defined at C:\Users\1\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=KeyError('city')>
Traceback (most recent call last):
  File "C:\Users\1\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\1\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\1\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "C:\Users\1\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
    return await self.message_handlers.notify(update.message)
  File "C:\Users\1\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "C:\Users\1\probiv.py", line 85, in answer_q2
    await message.reply(f'Город: {info["city"]}\nРегион: {info["region"]}\nСтрана: {info["country_name"]}\nВалюта: {info["currency"]}\nНаселение страны: {info["country_population"]}\nПровайдер: {info["org"]}')
KeyError: 'city'
Goodbye!

Ответы

Ответов пока нет.