I try to send InlineKeyboard but catch error TypeError: getattr(): attribute name must be string CODE:
async def send_afisha_to_channel(self,about: dict) -> None:
async with self.app:
await self.app.send_photo(
chat_id='@filmas_tiktok',
photo=about['img_link'],
caption=MessagePaterns.FILM_AFISH_PATTERN(about),
parse_mode='html',
reply_markup=KeyBoards.get_link_kb_pyro(about['shorturl'])
)
Class KeyBoards
class KeyBoards:
@staticmethod
def get_link_kb_pyro(url: str, text: str = 'Смотреть🎦') -> pyrokbmk:
btn = pyrokbbut(text,url=url)
kb = pyrokbmk(inline_keyboard=[btn])
return kb
Error
Traceback (most recent call last):
File "C:\Users\Kirill\PycharmProjects\test\venv\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\Kirill\PycharmProjects\test\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "c:\Users\Kirill\PycharmProjects\test\main.py", line 41, in admin_commands
await pyroClient.send_afisha_to_channel(about=about)
File "c:\Users\Kirill\PycharmProjects\test\contrib\utils.py", line 35, in send_afisha_to_channel
await self.app.send_photo(
File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\pyrogram\methods\messages\send_photo.py", line 180, in send_photo
reply_markup=await reply_markup.write(self) if reply_markup else None,
File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\pyrogram\types\bots_and_keyboards\inline_keyboard_markup.py", line 62, in write
for b in r:
File "C:\Users\Kirill\PycharmProjects\test\venv\lib\site-packages\pyrogram\types\object.py", line 94, in __getitem__
return getattr(self, item)
TypeError: getattr(): attribute name must be string
A keyboard button include url to site and text of button.
If I read this part right:
btn = pyrokbbut(text,url=url)
kb = pyrokbmk(inline_keyboard=[btn])
you're defining one button, and pass that as a list to the keyboard itself. Pyrogram and its InlineKeyboardMarkup require a list of lists, where the outer list is the rows, the inner list the buttons of each row.
You'll want something that looks like this:
keyboard = [ # List of rows:
[button, button], # First Row
[button], # Second Row
]