Python: Using if and else statements to loop

#1
I have written a scrip that requests a URL, if the response is is 'CAPCHA_NOT_READY' then the script should sleep for 5 seconds and then request the URL again. If the response starts with 'OK' then the scrip should continue.

I am not sure at how I set up this loop. Thanks, Piers.
Code:
r = requests.get(url)
print("Sending Captcha To 2captcha")
print("Captcha ID = "+(r.text))

time.sleep(5)

url2 = "http://2captcha.com/res.php?key="+api+"action=get&id="+(r.text)[3:]
print(url2)
r = requests.get(url2)
print(r.text)

if r.text == "CAPCHA_NOT_READY":
    time.sleep(5)
    r = requests.get(url2)
    print(r.text)
 
#2
So far what I understand you wanted to get the captcha from url and send it to url2 and request url2 in every 5 secs until is succeeded.
Code:
r = requests.get(url)
print("Sending Captcha To 2captcha")
print("Captcha ID = "+(r.text))
CAPTCHA_ID = r.text
time.sleep(5)

CAPTCHA_TEXT = True
while CAPTCHA_TEXT:
    url2 = "http://2captcha.com/res.php?key="+api+"action=get&id="+(CAPTCHA_ID)[3:]
    r = requests.get(url2)
    if r.text == 'CAPCHA_NOT_READY':
        time.sleep(5)
    if r.text == 'OK':
        CAPTCHA_TEXT = False