Коротко: необходимо открыть картинку и этой картинкой заменить прошлую:
with open('avatar/' + f'{idfot1}', 'rb') as file:
cat = types.InputMediaPhoto(file)
await bot.edit_message_media(chat_id=call.from_user.id, message_id=call.message.message_id, media=cat)
Но вылазиет ошибка - ValueError: I/O operation on closed file
Ошибка:ERROR:asyncio:Task exception was never retrieved
future: exception=ValueError('I/O operation on closed file')>
Traceback (most recent call last):
File "C:\Users\User\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\User\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\User\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\User\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 283, in process_update
return await self.callback_query_handlers.notify(update.callback_query)
File "C:\Users\User\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\User\Desktop\testsearchanon\main.py", line 871, in oz1
await bot.edit_message_media(chat_id=call.from_user.id, message_id=call.message.message_id, media=cat)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\bot\bot.py", line 2743, in edit_message_media
result = await self.request(api.Methods.EDIT_MESSAGE_MEDIA, payload, files)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\bot\base.py", line 231, in request
return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\bot\api.py", line 139, in make_request
async with session.post(url, data=req, **kwargs) as response:
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\aiohttp\client.py", line 1138, in __aenter__
self._resp = await self._coro
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\aiohttp\client.py", line 507, in _request
req = self._request_class(
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\aiohttp\client_reqrep.py", line 313, in __init__
self.update_body_from_data(data)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\aiohttp\client_reqrep.py", line 507, in update_body_from_data
body = body()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\aiohttp\formdata.py", line 170, in __call__
return self._gen_form_data()
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\aiohttp\formdata.py", line 163, in _gen_form_data
self._writer.append_payload(part)
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\aiohttp\multipart.py", line 831, in append_payload
size = payload.size
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\aiohttp\payload.py", line 379, in size
return os.fstat(self._value.fileno()).st_size - self._value.tell()
ValueError: I/O operation on closed file