0

The bot must accept the user's responses and send each of the responses to a text file, read each of the responses and send it to the database, an error occurs when writing responses to the database, but at the beginning of this there were no errors, the bot worked fine. I want to add that there were no changes in the code, it just stopped working.

    import telebot,json
    from tinydb import TinyDB, Query
    
    bot = telebot.TeleBot('')
    
    @bot.message_handler(commands = ['start'])
    def fh(m):
        bot.send_message(m.chat.id,'jik')
    
    
    @bot.message_handler(commands = ['otz']) 
    def dff(m):
        
        bot.send_message(m.chat.id,'day') 
        bot.register_next_step_handler(m, dabv) 
    
    def dabv(m):
        Ssilha = str(m.text)
        hbn = open(r'C:\Users\Admin\Desktop\Новая папка (2)\ssil.txt','w')
        hbn.write(Ssilha)
        
        bot.send_message(m.chat.id, 'day ots')
        bot.register_next_step_handler(m, otsifsek) 
    
    def otsifsek(m):
    
        Otsef = str(m.text)
    
        hbnv = open(r'C:\Users\Admin\Desktop\Новая папка (2)\com.txt', 'w')
        hbnv.write(Otsef)
        bot.send_message(m.chat.id, str(Otsef))
    
        bot.register_next_step_handler(m, ots)
    
    def ots(m):
        hbnn = open(r'C:\Users\Admin\Desktop\Новая папка (2)\ssil.txt', 'r')
        g = str(hbnn.read())
        h22 = open(r'C:\Users\Admin\Desktop\Новая папка (2)\com.txt', 'r')
        gnv = str(h22.read())
    
        ggg = {}
        ggg[g] = gnv
        print(ggg)
        dmc = Query()
    
    
        ggg = json.dumps(ggg)
        ggg = json.loads(ggg)
        print(ggg)
        ghh = [ggg]
    
        g123 = TinyDB(r'C:\Users\Admin\Desktop\Новая папка (2)\bd.txt')
        g123.insert(ggg)
    
    
    
    
    
    
        k = [g123.search(dmc.g == ghv)]
        bot.send_message(m.chat.id, k[0][g])
  
bot.polling()

Amnon
  • 2,212
  • 1
  • 19
  • 35
Takeda
  • 1
  • 1
  • Where was the error? Can you include the entire traceback message? – tdelaney Nov 13 '20 at 20:17
  • 1
    We can't help with this problem without getting more information. Did this line fail: `ggg = json.loads(ggg)` ? What does the bad data look like? The error says "line 2 column 1" - but how are we supposed to know what is in those lines? – tdelaney Nov 13 '20 at 20:33

0 Answers0