@eric_idle

Почему я не могу получить file_id для загруженного фото в телеграме?

Хочу загрузить фото на сервера Телеграма и получить их file_id для последующего использования.
Для загрузки использую следующую функцию на основе библиотеки pyTelegramBotApi:
def find_file_ids(message):
    for file in os.listdir('photo/'):
        if file.split('.')[-1] == 'jpg':
            f = open('photo/'+file, 'rb')
            res = bot.send_photo(message.chat.id, f, None)
            print(res)
        time.sleep(3)

Но res не содержит file_id, только следующее:
{'forward_from_chat': None, 'contact': None, 'pinned_message': None, 'left_chat_member': None, 'new_chat_member': None, 'entities': None, 'date': 1483956908, 'delete_chat_photo': None, 'supergroup_chat_created': None, 'venue': None, 'audio': None, 'text': None, 'from_user': {'username': 'nameBot', 'id': 289882736, 'last_name': None, 'first_name': 'Bot Name'}, 'new_chat_photo': None, 'chat': {'username': 'heyheyhey, 'id': 47302288, 'last_name': None, 'first_name': 'Maximus', 'type': 'private', 'title': None}, 'video': None, 'caption': None, 'migrate_to_chat_id': None, 'reply_to_message': None, 'edit_date': None, 'photo': [<telebot.types.PhotoSize object at 0x7f5627998e48>, <telebot.types.PhotoSize object at 0x7f5627998c88>, <telebot.types.PhotoSize object at 0x7f5627998d30>], 'group_chat_created': None, 'forward_date': None, 'voice': None, 'location': None, 'forward_from': None, 'new_chat_title': None, 'sticker': None, 'migrate_from_chat_id': None, 'document': None, 'channel_chat_created': None, 'message_id': 260, 'content_type': 'photo'}
  • Вопрос задан
  • 2582 просмотра
Пригласить эксперта
Ответы на вопрос 1
Johnnik
@Johnnik
Получилось вывести в консоль только так 8(
Получается только если кидаешь в телеграм фото, file_id которого хотим узнать, и следом выходит test.png >.< (руки кривые)

@bot.message_handler(content_types=['photo'])
def parse_all_photos(message):
f = open('data/img/test.png', 'rb')
res = bot.send_photo(message.chat.id, f, None)
print(message.photo[-1].file_id)
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы