Python except don't work. I'm trying
r = requests.get('URL') # URL returns something like: {"code": ["12345678"]}
print(r.text)
parse = json.loads(r.text)
getcode = False
while not getcode:
time.sleep(2)
codeparse = parse["code"]
print("Unable to get SMS Code, sleeping for 2 seconds...")
except KeyError:
pass
getcode = parse["code"]
I've tried everything I know. Is there something I need to import or something I'm missing?
Edit: Updated to add more code as requested.
except KeyErroris only going to detectKeyError. If you want it for all errors then useexcept Exception. But this will supress all error. Also,exceptshould always go withtrytryblock and python version.try