Как отправить фото в Telegram через библиотеку `pytelegrambotapi`?
import telebot
from telebot import types
from countryinfo import CountryInfo
country = CountryInfo("Argentina")
bot = telebot.TeleBot('TOKEN')
@bot.message_handler(commands=["start"])
def set_commands(message):
bot.send_photo(message.chat.id, country.flag())
bot.infinity_polling()
country.flag()
включает в себя вот эту ссылку
Ошибка такая: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: wrong file identifier/HTTP URL specified
Пробовал через библиотеку requests:
import telebot
from telebot import types
from countryinfo import CountryInfo
import reqests as r
country = CountryInfo("Argentina")
bot = telebot.TeleBot('TOKEN')
r = r.get(country.flag())
@bot.message_handler(commands=["start"])
def set_commands(message):
bot.send_photo(message.chat.id, r.content)
bot.infinity_polling()
Получал ошибку такую: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: IMAGE_PROCESS_FAILED
Пробовал создать папку, туда добавить картинку, а потом открыть эту картинку и отправить:
import telebot
from telebot import types
from countryinfo import CountryInfo
import requests as r
country = CountryInfo("Argentina")
bot = telebot.TeleBot('TOKEN')
f = open("C:/Users/messi/PycharmProjects/Country_bot/image", "wb")
fe = r.get(country.flag())
f.write(fe.content)
f.close()
@bot.message_handler(commands=["start"])
def set_commands(message):
photo = open("C:/Users/messi/PycharmProjects/Country_bot/image", 'rb')
bot.send_photo(message.chat.id, photo)
bot.infinity_polling()
Но получал ошибку такую: PermissionError: [Errno 13] Permission denied: 'C:/Users/messi/PycharmProjects/Country_bot/image'
Потом пробовал через os
, но все безуспешно..
Источник: Stack Overflow на русском