時運行下面的腳本時,我收到以下錯誤,可以anyhelp以確定是什麼問題,以及如何克服它類型錯誤運行命令
CODE: -
import sys
import os
def main():
to = ''
with open('caf_gerrits.txt','r') as f :
for gerrit in f :
print "Gerrit " + gerrit
cmd = "ssh -p 29418 review-android.company.com gerrit query --format=JSON --current-patch-set --commit-message --files \'%s\' >> gerrit_output.txt" %(gerrit)
os.system(cmd)
if __name__ == '__main__':
main()
錯誤: -
Gerrit 530731
Traceback (most recent call last):
File "test.py", line 14, in <module>
cmd = "ssh -p 29418 review-android.company.com gerrit query --format=JSON --current-patch-set --commit-message --files \'%s\' >> gerrit_output.txt" %(gerrit)
File "test.py", line 10, in main
to = ''
TypeError: must be string without null bytes, not str
您使用的是什麼版本的Python?我沒有得到CPython 2.7,Pypy 2.2或Jython 2.7b1的這個錯誤。 – dstromberg
我複製/粘貼並更改cmd,腳本工作。所以可能是你有些事情沒有在這裏顯示導致問題。從錯誤消息中,第10行是='',但我們沒有在你的源代碼中看到它。我們在這裏錯過了一些東西嗎? – PasteBT
@PasteBT - 我正在使用pythong 2.7.3,你是否創建了一個文件caf_gerrits並擁有一些像530731那樣的digist? – user2955256