Flask:风景函数未返回有效的响应tup

2024-09-30 08:35:50 发布

您现在位置:Python中文网/ 问答频道 /正文

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

这是我在执行代码时遇到的错误。在

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)

同时,我只得到循环中的第一个值,而我希望它遍历整个循环并打印出所有选项。在


Tags: answerurlreturnresponsestatusdiffbodyli

热门问题