1

The view function did not return a valid response tuple. To tuple must have the form (body, status, headers), (body, status), or (body, headers).

This was the error I got, when I was executing my code.

def success(name, diff, cat):
      url = "https://opentdb.com/api.php?amount=10&category="+cat+"&difficulty="+diff
      response = requests.get(url)
      fp = response.content
      obj = json.loads(fp)
      ans_li = ['abcd']

      for x in obj["results"]:
         question = x['question']
         answer = x['correct_answer']
         ans_li[0] = answer
         incorrect_ans = x['incorrect_answers']
         options = ans_li+incorrect_ans
         random.shuffle(options)
         makeitastring = '  '.join(map(str, options))
         makeitastring+=makeitastring
         app.logger.info(options)

      return tuple(options)

Also I am getting just first value in the loop, whereas I want it to traverse the entire loop and print out all options.

davidism
  • 121,510
  • 29
  • 395
  • 339

0 Answers0