C
C
Cockie2020-11-13 23:31:37
Python
Cockie, 2020-11-13 23:31:37

Why does json.decoder.JSONDecodeError: Expecting value: line2 occur?

The bot needs to take 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 while writing the responses to the database, but there were no errors at the beginning of this, 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()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question