Skip to content

[BUG] - error sending photo as file with inline keyboard #1888

@91DarioDev

Description

@91DarioDev

sending a photo as file with inline keyboard returns this error:

Traceback (most recent call last): File "test.py", line 4, in bot.send_photo(4746004, photo=f, reply_markup=InlineKeyboardMarkup([[InlineK eyboardButton(text='1', url='2')]])) File "", line 2, in send_photo File "C:\Users\Dario\AppData\Local\Programs\Python\Python37-32\lib\site-packag es\telegram\bot.py", line 70, in decorator result = func(*args, **kwargs) File "C:\Users\Dario\AppData\Local\Programs\Python\Python37-32\lib\site-packag es\telegram\bot.py", line 498, in send_photo **kwargs) File "C:\Users\Dario\AppData\Local\Programs\Python\Python37-32\lib\site-packag es\telegram\bot.py", line 176, in _message result = self._request.post(url, data, timeout=timeout) File "C:\Users\Dario\AppData\Local\Programs\Python\Python37-32\lib\site-packag es\telegram\utils\request.py", line 329, in post result = self._request_wrapper('POST', url, fields=data, **urlopen_kwargs) File "C:\Users\Dario\AppData\Local\Programs\Python\Python37-32\lib\site-packag es\telegram\utils\request.py", line 225, in _request_wrapper resp = self._con_pool.request(*args, **kwargs) File "C:\Users\Dario\AppData\Local\Programs\Python\Python37-32\lib\site-packag es\telegram\vendor\ptb_urllib3\urllib3\request.py", line 70, in request **urlopen_kw) File "C:\Users\Dario\AppData\Local\Programs\Python\Python37-32\lib\site-packag es\telegram\vendor\ptb_urllib3\urllib3\request.py", line 138, in request_encode_ body body, content_type = encode_multipart_formdata(fields, boundary=multipart_bo undary) File "C:\Users\Dario\AppData\Local\Programs\Python\Python37-32\lib\site-packag es\telegram\vendor\ptb_urllib3\urllib3\filepost.py", line 86, in encode_multipar t_formdata body.write(data) TypeError: a bytes-like object is required, not 'dict'

this is the snippet use to reproduce the error (use a picture on the disk) :

from telegram import InlineKeyboardMarkup, InlineKeyboardButton, Bot
bot = Bot('token')
with open('test.png', 'rb') as f:
    bot.send_photo(TELEGRAM_ID, photo=f, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(text='1', url='https://example.com')]]))

the snippet works on ptb 12.5.1 version, but not on 12.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions