为什么argparse with python 3.8对我来说带有相同前缀的标志会失败?

如何解决为什么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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?