Adapting code to SSL check in python 2.7.9 and changing sys.exit to exceptions