Search code examples
pythonattributeerrorpython-decoratorstry-except

How to restart decorator on error in python


I have a func() decorator, sometimes it throws an error when running AttributeError, but if you re-run the decorator, then everything works, I tried to fix it through try except, when an error is thrown 1 time, everything works, but if the error is thrown several times, then except doesn't work

    try:
        func()
    except AttributeError:
        print('Error login, try again')
        func() ```

Solution

  • while True:
        try:
            func()
            break
        except AttributeError:
            print('Error login, try again')