Pipe Delimiter in answer ( obtained from front end as json ) causing trouble and corrupting files

General Tech Bugs & Fixes . 2 years ago

  0   1   0   0   0 tuteeHUB earn credit +10 pts

5 Star Rating 5 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Write Your Comments or Explanations to Help Others



Tuteehub forum answer Answers (1)


profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

Whenever "answer" is having pipe delimiters in them, the files are getting corrupted and the record is not getting appended and further functionalities are disabling themselves.

@app.route("/append_record", methods = ['POST'])
def append_record():
    query = text_normalize_csv_diacritic(request.json["query"])
    #print query
    answer = text_normalize_csv_diacritic(request.json["answer"])
    #print answer
    module = request.json["module"]
    lang = request.json["lang"]
    isloop = request.json["is_loop"]
    csv_file = getfilefromdb(lang)
    #print csv_file.read()
    found = False
    questions=[]
    corpus = []
    lang_query = detect_language(query)
    lang_query_alt = detect_language(answer)
    #csv_file_r = csv.reader(csv_file.split('\n'), quotechar='"')
    csv_file_r = csv.reader(csv_file.splitlines(), quotechar='"')
    #print csv_file.read().splitlines()
    corpus = list(csv_file_r)
    #print corpus

    if lang_query_alt == lang_query and lang == lang_query:

        for t in corpus[1:]:
            try:
                if len(t) > 1:
                    questions.append(t[0])
        #print questions

            except Exception as e:
                return jsonify(error=str(e))

        if query not in questions:
            corpus.append([query, answer, module, isloop])

        else:
            index = questions.index(query)
            index+=1

            if corpus[index][1]== answer:

                return jsonify(error="already exists")
            else:
                corpus[index][1] = answer

    #print "\n".join(",".join(corpora).decode("utf-8","ignore") for corpora in corpus)

    else:
        return jsonify(error="Please make sure that you have selected your language appropriately")

    try:
        putfileindb("\n"
                                                    
                                                    
0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community