Python Docopt使用菜单问题



im我相信我认为是由我的用法描述引起的,但不能弄清原因。这个想法是获取文件中有效用户的列表(用户名密码),将其分为字典并返回字典。然后获取服务器文件(IP perline),将其变成列表。然后,请致电MTSTC,将子过程称为.rdp conf文件,或直接输入CLI(还没有到远)

任何帮助将不胜感激。

错误

unknown@ubuntu:~$ ./rdpcheck.py -u userpass.txt -s servers.txt
Traceback (most recent call last):
  File "./rdpcheck.py", line 30, in <module>
    arguments = docopt(__doc__, version='0.1a')
  File "/usr/local/lib/python2.7/dist-packages/docopt.py", line 560, in docopt
    pattern = parse_pattern(formal_usage(DocoptExit.usage), options)
  File "/usr/local/lib/python2.7/dist-packages/docopt.py", line 373, in parse_pattern
    result = parse_expr(tokens, options)
  File "/usr/local/lib/python2.7/dist-packages/docopt.py", line 387, in parse_expr
    seq = parse_seq(tokens, options)
  File "/usr/local/lib/python2.7/dist-packages/docopt.py", line 396, in parse_seq
    atom = parse_atom(tokens, options)
  File "/usr/local/lib/python2.7/dist-packages/docopt.py", line 415, in parse_atom
    raise tokens.error("unmatched '%s'" % token)
docopt.DocoptLanguageError: unmatched '('

代码

#!/usr/bin/python
"""
Script to check valid login credentials have ability to rdp to list of server.
Usage:
  rdpcheck.py (-u <user>) (-s <server>)
  rdpcheck.py -h | --help
Options:
  -u --user
  -s --server
  -h --help This help screen this screen.
"""
from docopt import docopt
def getuserpass(userpass):
        list = {}
        with open(userpass, 'r') as text:
                for line in text:
                        key, value = line.split()
        return list
def getservers(servers):
        slist = open(servers).readlines()
        return [s.replace('n', '.') for s in slist]
if __name__ == "__main__":
        arguments = docopt(__doc__, version='0.1a')
        print arguments

看来我错过了 - version选项。

新代码

#!/usr/bin/python
"""
Description:
Users to test a list of credentials against a list of servers
Usage:
  rdpcheck.py (-u <FILE>) (-s <FILE>)
  rdpcheck.py -h | --help
  rdpcheck.py --version
Options:
  -h --help     Show this screen.
  --version     Show version.
  -u --user=FILE
  -s --server=FILE
"""
from docopt import docopt
def getuserpass(userpass):
        list = {}
        with open(userpass, 'r') as text:
                for line in text:
                        key, value = line.split()
        return list
def getservers(servers):
        slist = open(servers).readlines()
        return [s.replace('n', '.') for s in slist]
if __name__ == "__main__":
        arguments = docopt(__doc__, version='0.1a')
        print arguments

相关内容

  • 没有找到相关文章

最新更新