【问题标题】:AttributeError: 'CalledProcessError' object has no attribute 'output'AttributeError:“CalledProcessError”对象没有属性“输出”
【发布时间】:2012-01-08 04:29:11
【问题描述】:

...在 Ubuntu 10.04 上使用 AutoKey 0.81.4

  1. 对 Linux 比较陌生(
  2. 这是我写的第一个 python

以下 AutoKey 脚本一直失败并出现以下错误。我在这里没有得到什么??

Script name: 'find files script'
Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/autokey/service.py", line 442, in execute
    exec script.code in self.scope
  File "<string>", line 13, in <module>
AttributeError: 'CalledProcessError' object has no attribute 'output'

脚本

import time

time.sleep(0.10)
retCode, args =  dialog.input_dialog("Files to Find","enter a file name")
fmt = "find / -name \"{0}\" -type f -print 2>/dev/null "
if retCode == 0:
    if len(args) > 0:
        cmd = fmt.format(args)
        #dialog.info_dialog(title="the command",message=cmd)
        try:
            rc = system.exec_command(cmd, getOutput=True)
        except subprocess.CalledProcessError, e:
            dialog.info_dialog(title="the return",message=str(e.output))

【问题讨论】:

  • system.exec_command 来自哪个模块?

标签: python autokey


【解决方案1】:

输出属性直到 Python 2.6 才存在。您可以使用 subprocess.Popen 和communicate()。或者您可以在this 之后反向移植 subprocess.check_output(也不是 2.6)。

【讨论】:

    【解决方案2】:

    将 e.output 更改为仅 e。使用 str(e) 将为您提供错误字符串。您可能需要查找异常以找出它们支持的属性。我不认为输出是其中之一。

    【讨论】:

    • 这是不正确的。在 CalledProcessException 上的 str(e) 给出:“命令 '' 返回非零退出状态 ”。 docs 表示 e.output 应该显示子进程的输出。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    • 2019-01-20
    • 2012-12-01
    • 2021-04-19
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多