Fixed the issue.
try:
location = pyautogui.locateOnScreen('1.png', confidence=0.9)
if pyautogui.locateOnScreen('1.png', confidence=0.9):
call_count = 0
if pyautogui.locateOnScreen('1.png', confidence=0.9):
while call_count <= 7:
logging.info(call_count)
call_count += 1
if has_restarted:
return
restarting_function(True)
restarting_function()
except pyautogui.ImageNotFoundException:
pass