实现 While 循环时出现 SyntaxError

SyntaxError when implementing While Loop

背景 -
我正在尝试在函数中实现逻辑,该函数在 'Code Block #1' 为真 (while True "meta" not in api_response:) 时不断循环,循环之间有 60 秒的中断。

如果代码块 #2 为真(except "meta" in api_response:"),那么我想 return api_response,准备好被另一个函数调用。

函数-

def unpack_response():
    api_response = api_call()
# Code Block # 1    
     while True "meta" not in api_response:
        meta_value = "meta"
        res = [val[meta_value] for key, val in response.items() if meta_value in val]
        meta_value = "".join(res)
        percent_value = "percent_complete"
        res = [val[percent_value] for key, val in response.items() if percent_value in val]
        percent_value = "".join(res)
        print(f' Your data requested, associaed with ID: {meta_value} is {percent_field} complete!')
        time.sleep(60)
            continue
# Code Block# 2
     except "meta" in api_response:
        return api_response
     break

问题 - 目前,我似乎得到以下 SyntaxError:

  File "<ipython-input-212-0757814896ea>", line 3
    while True "meta" not in api_response:
               ^
SyntaxError: invalid syntax

我哪里错了?

下面的代码是根据您的代码和要求编辑的,添加了 5 次迭代的中断,因为您的条件没有合适的中断可用。 您得到的语法错误是因为,您需要在 orand.

之间添加一些布尔操作数

def unpack_response():
    count=0
    api_response = api_call()
# Code Block # 1    
     while "meta" not in api_response:#no need of true
        count++
        meta_value = "meta"
        res = [val[meta_value] for key, val in response.items() if meta_value in val]
        meta_value = "".join(res)
        percent_value = "percent_complete"
        res = [val[percent_value] for key, val in response.items() if percent_value in val]
        percent_value = "".join(res)
        print(f' Your data requested, associaed with ID: {meta_value} is {percent_field} complete!')
        if "meta" in api_response:
            return api_response
        if count==5:
            break
        time.sleep(60)