I
I
irishka792021-09-02 18:21:05
Python
irishka79, 2021-09-02 18:21:05

Why don't images work in python telegram?

What am I doing wrong ?

mistake:

(util.py:75 WorkerThread1) ERROR - TeleBot: "ApiTelegramException occurred, args=('A request to the Telegram API was unsuccessful. Error code: 400 Description: Bad Request: type of file mismatch',)
Traceback (most recent call last):
File "C:\Users\bot\PycharmProjects\bot1\venv\lib\site-packages\telebot\util.py", line 69, in run
task(*args, **kwargs)
File "C:/ Users/bot/PycharmProjects/bot1/bot.py", line 17, in start
bot.send_photo(message.chat.id, PHOTO_1)
File "C:\Users\bot\PycharmProjects\bot1\venv\lib\site-packages \telebot\__init__.py", line 699, in send_photo
apihelper.send_photo(self.token, chat_id, photo, caption, reply_to_message_id, reply_markup,
File "C:\Users\bot\PycharmProjects\bot1\venv\lib\site-packages\telebot\apihelper.py", line 352, in send_photo
return _make_request(token, method_url, params=payload, files=files, method= 'post')
File "C:\Users\bot\PycharmProjects\bot1\venv\lib\site-packages\telebot\apihelper.py", line 108, in _make_request
json_result = _check_result(method_name, result)
File "C:\ Users\bot\PycharmProjects\bot1\venv\lib\site-packages\telebot\apihelper.py", line 135, in _check_result
raise ApiTelegramException(method_name, result, result_json)
telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400 Description: Bad Request: type of file mismatch
"
2021-09-02 17:16:53,118 (__init__.py:455 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. Error code: 400 Description: Bad Request: type of file mismatch"

Process finished with exit code 0


The code itself:
import telebot
from telebot import types

TOKEN = '788777847:AAHvy-O3o838Tx1LVSAMCGjIOP0cWXw1WhY'

PHOTO_1 = 'AAMCAgADGQEAAgFPYTDnPGLRFY_rKXWyXzWWYjVnEocAAksSAAKRhYhJL9xN-MfUM-QBAAdtAAMgBA'

bot = telebot.TeleBot(TOKEN)

@bot.message_handler(commands=['start'])
def start(message):
    startmenu = types.ReplyKeyboardMarkup(True, True)
    startmenu.row('hello?')
    bot.send_photo(message.chat.id, PHOTO_1)
    bot.send_message(message.chat.id, 'Привет! как отпраить картинку?. ', reply_markup=startmenu)

bot.polling()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Old_TyT, 2021-09-04
@irishka79

Here is a piece of echo bot code for working with photos

@dp.message_handler(content_types=['photo'])
async def handle_docs_photo(message):
    await bot.send_photo(message.from_user.id, message.photo[-1].file_id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question