我在这里做错什么了。我的第一个循环运行,但不运行if语句。第二个循环不运行。这是与5sim.net api一起使用的。
while 'PENDING' in sms['status']:
sms = get_status(headers, id)
time.sleep(5)
print('Waiting for phone no. to get activated.')
if sms['status'] == 'RECIEVED':
print('Phone no. is activated.')
break
sms = get_status(headers, id)
time.sleep(2)
while 'RECIEVED' in sms['status']:
sms = get_status(headers, id)
time.sleep(5)
print('Waiting for SMS code')
if sms['status'] == 'FINISHED':
break sms是一个json
{'id': xxxxxxx, 'phone': '+xxxxxxxx', 'operator': 'abc', 'product': 'abc', 'price': 24, 'status': 'PENDING', 'expires': '2021-08-21T22:15:39.068961Z', 'sms': [], 'created_at': '2021-08-21T22:00:39.068961Z', 'country': 'usa'}发布于 2021-08-21 22:09:30
它不会改变。您需要手动更改sms["status"]。否则就无法中断循环,if语句位于while循环中,因此如果while不运行,if语句也不会运行。可能添加一种更改sms“状态”的方法,否则循环将不会运行。
https://stackoverflow.com/questions/68877011
复制相似问题