D
D
Dmitry Loginov2019-09-03 18:01:58
Python
Dmitry Loginov, 2019-09-03 18:01:58

How to send a photo via telegram api?

Good afternoon.
I'm trying to teach a bot to send photos.

def send_photo(chat_id, photo):
    url = URL + 'sendPhoto'
    answer = {'chat_id':chat_id, 'photo':photo}
    r = requests.post(url, json=answer)
    return r.json()

f = open("C:\\Python37\\project\\photo\\1.jpg", 'rb')
send_photo(chat_id, f)

Python throws an error:
TypeError: Object of type BufferedReader is not JSON serializable
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Barbolin, 2019-09-03
@Gusik1984

What library are you using?
import telebot
from telebot import types
img = open(imageFile, 'rb')
bot.send_photo(chatID, img, caption=TEST)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question