我有以下方法:
def PopulateStaticDetails(args):
confParser = ConfigParser.SafeConfigParser()
confParser.read(args.configFile)
generator = ''
emails = ''
certType = ''
# ---- Cert Server Check ---- #
if args.generator is None:
try: generator = confParser.get('Certificate Generator', 'server').strip()
except:
log.fatal('No certificate generator server designated. Please check your configuration.')
log.fatal('Exiting.')
exit(1)
else:
generator = args.generator
# ---- Cert Type Check ---- #
if args.certType is None:
try: certType = configParser.get('Application Settings', 'cert').strip()
except:
print "Unexpected error:", sys.exc_info()[0]
log.fatal('No certificate type was designated. Please check your configuration.')
exit(1)
else:
certType = args.certType
if certType not in ('2011', '2013', '2015'):
log.fatal('Invalid certificate type: {}'.format(certType))
exit(1)
# ---- Email List Check ---- #
if args.emails is None:
try:
emails = confParser.get('Application Settings', 'emails').strip().split('\n')
if emails == ['']: raise
except:
log.warn('No email address specified to send results to.')
else:
emails = args.emails
destDir = '{}/{}'.format(args.destdir,certType)
certPass = getpass.getpass(prompt="Enter your password for access before proceeding:\n")
return StaticDetails(generator, args.certuser, certType, certPass, emails, destDir)
使用以下配置:
[Application Settings]
servers:
serv.a.com
serv.b.com
serv.c.com
cert: 2015
emails: me@supbro.com
我得到以下输出:
Unexpected error: <type 'exceptions.NameError'>
[2015-04-09 17:43:33,911] | ssl-setup - CRITICAL - No certificate type was designated. Please check your configuration.
如果我在命令行--cert 2015
上指定它,它会继续成功。为什么emails:
部分工作正常,但cert:
部分没有?我确信这里有一些简单的东西,我只是忽略了......