From 81100f249cbec7f89f07c0fd62e02b397399bb96 Mon Sep 17 00:00:00 2001 From: Artem Frantsiian <35114937+ArtemFrantsiian@users.noreply.github.com> Date: Sat, 29 Aug 2020 21:57:41 +0300 Subject: [PATCH] Fix an error with the is_pil_image function When I've tried to send_photo as shown in detailed_example, I got an error: "AttributeError: module 'PIL' has no attribute 'Image'". This error was described well here: https://stackoverflow.com/a/11911536/9092263. So in accordance to prescriptions, I've made changes and It works fine for me. Steps to reproduce: 1. initiate bot via TeleBot constructor 2. call function bot.send_photo(call.message.chat.id, open("some_image.jpg", "rb")) P.S. Error Environment: - python==3.8.5 - pyTelegramBotAPI==3.7.3 - PIL==7.2.0 --- telebot/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/telebot/util.py b/telebot/util.py index 099828a..438e8c1 100644 --- a/telebot/util.py +++ b/telebot/util.py @@ -11,7 +11,7 @@ import queue as Queue import logging try: - import PIL + from PIL import Image from io import BytesIO pil_imported = True except: @@ -164,7 +164,7 @@ def is_bytes(var): return isinstance(var, bytes) def is_pil_image(var): - return pil_imported and isinstance(var, PIL.Image.Image) + return pil_imported and isinstance(var, Image.Image) def pil_image_to_file(image, extension='JPEG', quality='web_low'): if pil_imported: