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)
我也只是在循环中得到第一个值,而我希望它遍历整个循环并打印出所有选项。