updated getconnection method

improved handling of error with else rather than elif