为什么python 3.8中的argparse在使用相同前缀的标志时失败了



这个问题在@abbra提到的下一个freeipa版本中已经过时了。

有人能告诉我为什么会出现以下错误吗?

An unexpected error occurred:
argparse.ArgumentError: argument --ipa--h/--host_name/--host: conflicting option strings: --host_name, --host

代码:

@zope.interface.implementer(certbot.interfaces.IAuthenticator)
@zope.interface.provider(certbot.interfaces.IPluginFactory)
class Authenticator(certbot.plugins.dns_common.DNSAuthenticator):
""" FreeIPA / Red Hat Enterprise Linux IdM authentication using DNS challenges """
description = __doc__.strip().split("n", 1)[0]
def __init__(self, *args, **kwargs):
# Maps provided domains to IPA zones
self.zone_map = {}
super(Authenticator, self).__init__(*args, **kwargs)

@classmethod
def add_parser_arguments(cls, add, default_propagation_seconds=10):
super(Authenticator, cls).add_parser_arguments(add, default_propagation_seconds)
add('-h', '--host_name', '--host', dest='ipa_host', help='Hostname or IP Address of the IPA (Satellite) server')
add('-d', '--ipa_domain_name', '--ipa_domain', dest='ipa_domain', help='Domain in IPA (Satellite) to register under')
add('-H', '--xml_rpc_url', '--xmlrpc-url', dest='ipa_xml_rpc_url', help='XML RPC service location')
add('-C', '--ca_path', '--capath', dest='ca_path', help='Path do a directory containing PEM encoded CA files')
add('-c', '--ca_file', '--cafile', dest='ca_file', help='Path do a file containing PEM encoded CA certificates')
add('-t', '--keytab_name', '--keytab-name', dest='keytab_file', help='Path to a keytab file containing credentials for IPA server authentication')
add('-k', '--submitter_principal', '--submitter-principal', dest='submitter_principal', help='Kerberos principal for IPA server authentication')
add('-K', '--use_ccache_creds', '--use-ccache-creds', dest='use_ccache_creds', default=False, action='store_true', help='Use default ccache for authorization instead of authenticating')
add('-P', '--request_principal', '--principal-of-request', dest='request_principal', help='Principal(s) (FQDN) used in signing request, comma separated')
add('-T', '--request_profile', '--profile', dest='request_profile', help='Use a specific profile when requesting enrollment')

完整的代码托管在Github上。我正试图将其移植到python 3.8,因为这是最近的fedora 32 python版本。

提前谢谢,请客气。我是个不折不扣的Python新手。

您需要使用allow_abbrev=False创建ArgumentParser的实例。

说明:--host--host-name的缩写。默认情况下,允许使用缩写。因此,--host已经被--host-name覆盖。

或者,去掉--host,因为它无论如何都会被--host-name匹配。

请参阅文档:https://docs.python.org/3/library/argparse.html#allow-缩写

最新更新