The difference in my question is that I don't have the "resp" variable in the code I'm running.
How can I solve this problem?
What needs to be added?
Token is hidden
The code
from aiogram import Bot, Dispatcher, executor, types
import python_weather
bot = Bot(token="")
dp = Dispatcher(bot)
client = python_weather.Client(format=python_weather.IMPERIAL, locale="ru-RU")
@dp.message_handler()
async def echo(message: types.Message):
weather = await client.find(message.text)
celsius = round((weather.current.temperature - 32) / 1.8)
resp_msg = weather.location_name + "
"
resp_msg += f"??????? ???????????: {celsius}
"
resp_msg += f"????????? ??????: {weather.current.sky_text} "
await message.answer(resp_msg)
if __name__ == "__main__":
executor.start_polling(dp, skip_updates=True)
The Error
Task exception was never retrieved
future: <Task finished name='Task-16' coro=<Dispatcher._process_polling_updates() done, defined at B:Pythonday2venvlibsite-packagesaiogramdispatcherdispatcher.py:407> exception=UnboundLocalError("local variable 'resp' referenced before assignment")>
Traceback (most recent call last):
File "B:Pythonday2venvlibsite-packagesaiogramdispatcherdispatcher.py", line 415, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "B:Pythonday2venvlibsite-packagesaiogramdispatcherdispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "B:Pythonday2venvlibsite-packagesaiogramdispatcherhandler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "B:Pythonday2venvlibsite-packagesaiogramdispatcherdispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "B:Pythonday2venvlibsite-packagesaiogramdispatcherhandler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "B:Pythonday2ot.py", line 12, in get_weather
weather = await client.find(message.text)
File "B:Pythonday2venvlibsite-packagespython_weatherclient.py", line 37, in find
return await self.http.request(location)
File "B:Pythonday2venvlibsite-packagespython_weather
est.py", line 28, in request
elif resp.status >= 400:
UnboundLocalError: local variable 'resp' referenced before assignment
Any suggestions?