G
G
Gleb Lukashonok2019-09-20 21:30:10
Python
Gleb Lukashonok, 2019-09-20 21:30:10

(-2147221008, 'CoInitialize was not called.', None, None) — What to fix?

Hello!
The code:

import telebot
import constant
bot = telebot.TeleBot(constant.API_TOKEN)
@bot.message_handler(content_types=['document'])    
def handle_file(message):
    try:
        chat_id = message.chat.id
        file_info = bot.get_file(message.document.file_id)
        downloaded_file = bot.download_file(file_info.file_path)
        src = u'D:\\Python\\Bot\\' + message.document.file_name
        with open(src, 'wb') as new_file:         # Сохраняем присланый от пользователя файл
            new_file.write(downloaded_file)
        from importlib import reload
        import tableTOtable
        while True:
            reload(tableTOtable)          #Запускается обработчик файла
            break                                               
        doc = open('D:\\Python\\Bot\\Счет-фактура.pdf', 'rb')
        bot.send_document(chat_id, doc)
        #bot.send_document(chat_id, "FILEID")
        #bot.sendDocument(chat_id, data, {fileName: 'file.pdf'});
        
    except Exception as e:
        bot.reply_to(message, e)
    from importlib import reload
    import kill_procces     # Закрывается процесс эксэля
    while True:
            reload(kill_procces)          #Запускается обработчик файла
            break        # Удаляется больше не нужный файл
    from importlib import reload
    import delete    
    while True:
        reload(delete)
        break
bot.polling(none_stop=True, interval=0)

The first time everything works, but on the second time the bot crashes and the telegram replies:
(-2147221008, 'CoInitialize was not called.', None, None)

Tell the noob how to solve the problem, please!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elvis, 2019-09-20
@Dr_Elvis

https://ru.stackoverflow.com/questions/288595/pyth...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question