Python配置解析器为一个值而不是其他值引发异常

2024-05-12 15:26:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下方法:

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:部分工作不正常?我肯定这里有些简单的东西我只是忽略了。。。你知道吗


Tags: nocomlogyourcertifchecktype