TypeError:execv()arg 2必须只包含使用docopt的字符串

时间:2014-10-30 12:06:58

标签: python subprocess docopt

我在传递参数时遇到以下错误。任何人都可以帮我识别这个问题吗?我在终端中将指令传递给我的函数,如下所示:

python makeQuicktime.py -i /Volumes/P003A/TM_Cloud/Nagrania/Karta_04/XDROOT/Clip/D004C010_141026MM.MXF -f 25 -c prores

这是函数 - 正如您所见,我试图将参数--codec作为字符串传递:

if __name__ == "__main__":
    args = docopt(__doc__, version='makeQuicktime 0.0.1')
    print args
    cmd_args = ""
    codec=str(args['--codec'])

    makeQuicktime( args['--input'], fps=args['--fps'], codec=str(args['--codec']) )

    os._exit(0)

此代码正在运行的其他函数的一部分(makeProRes,第110行是输出变量):

subprocess.call([FFMPEG_PATH, 'i', input,
    '-start_number', start_frame, '-r', fps,
    '-c:v', 'prores',
    '-profile:v', '2',
    '-c:a', 'copy',
    '-threads', cpus,
    output
  ])

错误:

Traceback (most recent call last):
  File "makeQuicktime.py", line 123, in <module>
    makeQuicktime( args['--input'], fps=args['--fps'], codec=str(args['--codec']) )
  File "makeQuicktime.py", line 53, in makeQuicktime
    makeProRes(1, input, fps, output)
  File "makeQuicktime.py", line 110, in makeProRes
    output
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 524, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1308, in _execute_child
    raise child_exception
TypeError: execv() arg 2 must contain only strings

1 个答案:

答案 0 :(得分:1)

start_framefpscpus中的一个是数字而不是字符串。当您找到哪个时,请将其括在str()中进行转换。