Не получается забрать из машины состояний данные + ошибка
Вкратце - я пишу telegram бота на Python. Идея - бот должен при нажатии на inline-кнопку через машину состояний получить от пользователя название интересующего его города и при нажатии на вторую inline-кнопку вывести погоду в этом городе. При нажатии на кнопку для ввода города бот запрашивает у пользователя город и в этом месте перестаёт работать. Ещё он иногда высылает вот такую ошибку:
Traceback (most recent call last):
File "C:\Users\belog\weather_bot\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 380, in start_polling
updates = await self.bot.get_updates(
File "C:\Users\belog\weather_bot\venv\lib\site-packages\aiogram\bot\bot.py", line 97, in get_updates
result = await self.request(api.Methods.GET_UPDATES, payload)
File "C:\Users\belog\weather_bot\venv\lib\site-packages\aiogram\bot\base.py", line 208, in request
return await api.make_request(self.session, self.server, self.__token, method, data, files,
File "C:\Users\belog\weather_bot\venv\lib\site-packages\aiogram\bot\api.py", line 140, in make_request
return check_result(method, response.content_type, response.status, await response.text())
File "C:\Users\belog\weather_bot\venv\lib\site-packages\aiogram\bot\api.py", line 119, in check_result
exceptions.ConflictError.detect(description)
File "C:\Users\belog\weather_bot\venv\lib\site-packages\aiogram\utils\exceptions.py", line 140, in detect
raise err(cls.text or description)
aiogram.utils.exceptions.TerminatedByOtherGetUpdates: Terminated by other getupdates request; make sure that only one bot instance is running
Cause exception while getting updates.
Вот код бота: main.py
from aiogram import Bot, Dispatcher, types
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters import Command
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
from aiogram.utils import executor
import config
from config import mgr
from states import ChoiceCity
bot = Bot(token=config.BOT_TOKEN)
dp = Dispatcher(bot, storage=MemoryStorage())
@dp.message_handler(Command(["start", "help"]))
async def start(message: types.Message):
keyboard = InlineKeyboardMarkup(inline_keyboard=[
[
InlineKeyboardButton(
text="? Выбрать город ?",
callback_data="city"
),
InlineKeyboardButton(
text="?Узнать погоду?",
callback_data="weather"
)
]
])
await message.answer("Привет, это WeatherBot! Ты можешь узнать у меня погоду ?", reply_markup=keyboard)
@dp.callback_query_handler(text="city")
async def type_city(call: CallbackQuery):
await call.message.answer("Отправьте название города, погоду которого вы хотите узнать:")
await ChoiceCity.city.set()
await call.answer()
@dp.message_handler(state=ChoiceCity.city)
async def save_place(message: types.Message, state: FSMContext):
place = message.text
async with state.proxy() as data:
data["place1"] = place
@dp.callback_query_handler(text="weather")
async def send_weather(call: CallbackQuery, state: FSMContext):
data = await state.get_data()
place = data.get("place1")
observation = mgr.weather_at_place(str(place))
w = observation.weather
t = w.temperature("celsius")
await call.message.answer(f"В городе {place} {t['temp']}°, ощущается как {t['feels_like']}°")
await call.answer()
executor.start_polling(dp)
states.py
from aiogram.dispatcher.filters.state import StatesGroup, State
class ChoiceCity(StatesGroup):
city = State()
Помогите плиз.