我在运行下面的脚本时遇到以下错误,可以帮助确定问题是什么以及如何克服它
import subprocess
import sys
import os
def main ():
to = ''
ssh_command = ["ssh", "-p", "29418", "review-android.quicinc.com", "gerrit",
"query", "--format=JSON", "--current-patch-set",
"--commit-message", "--files", ]
with open('gerrit_output.txt', 'a') as fp:
with open('caf_gerrits.txt','r') as f :
for gerrit in f :
print gerrit
result = subprocess.check_output(ssh_command + [gerrit, ])
print result
fp.write(result)
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
错误:-
545804
Traceback (most recent call last):
File "test.py", line 20, in <module>
File "test.py", line 15, in main
File "/usr/lib/python2.7/subprocess.py", line 537, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
TypeError: execv() arg 2 must contain only strings
Run Code Online (Sandbox Code Playgroud)
mgi*_*son 26
第三个元素ssh_command是整数.它需要是一个字符串.
例如:
ssh_command = ["ssh", "-p", 29418, ...
# ^ problem
Run Code Online (Sandbox Code Playgroud)
解决方案很简单,只需添加一些引号:
ssh_command = ["ssh", "-p", "29418", ...
# ^Now it's a string.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26708 次 |
| 最近记录: |