ошибка при отправке файла в telegram боте

программа должна делать простейшую обработку фото, но при конечной отправке фото программа выдаёт ошибку

No error handlers are registered, logging exception.
Traceback (most recent call last):
  File ..., line 555, in process_update        
    handler.handle_update(update, self, check, context)
  File ..., line 626, in handle_update
    new_state = handler.handle_update(update, dispatcher, check_result, context)
  File ..., line 198, in handle_update
    return self.callback(update, context)
  File ..., line 56, in print_dannn
    context.bot.send_document(update.effective_chat.id, photo)
  File ..., line 130, in decorator
    result = func(*args, **kwargs)
  File ..., line 959, in send_document
    'document': parse_file_input(document, Document, filename=filename),
  File ..., line 143, in parse_file_input
    return InputFile(file_input, attach=attach, filename=filename)
  File ..., line 62, in __init__
    self.input_file_content = obj.read()
  File ... line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 334: character maps to <undefined>

а это сам код

from telegram import Bot
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, ConversationHandler, CallbackContext
from credits import bot_token
from PIL import Image, ImageFont, ImageDraw

bot = Bot(token=bot_token)
updater = Updater(token=bot_token)
dispatcher = updater.dispatcher
O_D0 = 0
O_D1 = 1
CTT0 = 2
CTO = None
mesa0 = ''
mesa1 = ''


def obres(toch1,toch2,toch3,toch4,user):
    photo = Image.open(user + '_photo.jpg')
    photo = photo.convert('RGB')
    photo_crop = photo.crop((int(toch1),int(toch2),int(toch3),int(toch4)))
    photo_crop.show()
    photo_crop.save(user + '_photo.jpg')




def start(update,context):
    context.bot.send_message(update.effective_chat.id,text='давайте начнём нашу работу с обрезкой. Если хотите начать вышлите фото')
    return  O_D0


def photo_conv(update,context):
    user = str(update.effective_chat.id)
    photo_file = update.message.document.get_file()
    photo_file.download(user + '_photo.jpg')
    context.bot.send_message(update.effective_chat.id,'введите координаты первой точки обрезки')
    return O_D1


def obres_dannie1(update,context):
    global mesa0
    mesa0 = update.message.text
    context.bot.send_message(update.effective_chat.id,'введите координаты второй точки обрезки')
    return CTT0

def print_dannn(update,context):
    global mesa0,mesa1
    user = str(update.effective_chat.id)
    mesa1 = update.message.text
    toch0 = mesa0.split(' ')[0]
    toch1 = mesa0.split(' ')[1]
    toch2 = str(mesa1).split(' ')[0]
    toch3 = str(mesa1).split(' ')[1]
    obres(toch0,toch1,toch2,toch3,user)
    photo = open(user+'_photo.jpg')
    context.bot.send_document(update.effective_chat.id, photo)
    return ConversationHandler.END


start_handler = CommandHandler('start',start)
obres1 = MessageHandler(Filters.text,obres_dannie1)
print_dannn_handler = MessageHandler(Filters.text,print_dannn)
photo_conv_handler = MessageHandler(Filters.document.category("image"),photo_conv)
conv_handler = ConversationHandler(
    entry_points=[start_handler],
    states={
        O_D0 :[photo_conv_handler],
        O_D1 :[obres1],
        CTT0 :[print_dannn_handler]
    },
    fallbacks=[]
)    
dispatcher.add_handler(conv_handler)

updater.start_polling()
updater.idle()

Ответы (0 шт):