如何解决为什么argparse with python 3.8对我来说带有相同前缀的标志会失败?
这个问题在@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新手。
解决方法
您需要使用ArgumentParser
创建allow_abbrev=False
的实例。
说明:--host
是--host-name
的缩写。默认情况下,允许使用缩写。因此,--host
已涵盖--host-name
。
或者,只需省略--host
,因为无论如何它将与--host-name
匹配。
查看文档:{{3}}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。