GatewayException: Login failed

I am trying to process some autologin scripts which Identify the machineName for certain HMIs to be locked to particular machines and those users and passwords are retrieved from the database.
No matter what error handling I add, I cannot seem to stop the error window popping up with GatewayException: Login failed.
If there is an error with username or password, I just want to be able to default to a low-level operator login but I cannot stop this error popping up if login fails when calling system.security.switchUser(user,pwd)
I just put a basic example script below.
def loadHMISettings():
try:
print ‘loading loadHMISettings’
user=‘Myusername’
pwd=‘myPassword’
if not system.security.switchUser(user,pwd):
print ‘Failed login, try default’
system.security.switchUser(‘operator’,‘operator’)
except:
print ‘an exception occured’
system.security.switchUser(‘operator’,‘operator’)
Any suggestions?

Use validateUser() before trying to switchUser(). That’ll give you an opportunity to handle the invalid credentials before the switch.

1 Like