【发布时间】:2021-12-03 21:24:44
【问题描述】:
我尝试了这个solution answer 来解决我的问题,但是在使用该解决方案时我得到了这个错误:
Traceback (most recent call last):
File "version_build.py", line 125, in <module>
if __name__=='__main__': main()
File "version_build.py", line 113, in main
change = p4change(p4)
File "version_build.py", line 90, in p4change
change = p.communicate(changespec)[0]
File "C:\Python36\Lib\subprocess.py", line 843, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "C:\Python36\Lib\subprocess.py", line 1086, in _communicate
self._stdin_write(input)
File "C:\Python36\Lib\subprocess.py", line 781, in _stdin_write
self.stdin.write(input)
TypeError: a bytes-like object is required, not 'str'
我的主要问题是:为什么我会收到此错误,我是否在其他问题的解决方案中遗漏了什么?
我正在使用 python3。
我尝试使用 str.encode() 函数,但是在将变量打印到控制台时,它是空白的。 b''
这是失败的线路(主要是 p.communicate 线路):
changespec = 'change: new\n' + description
p = subprocess.Popen([p4, 'change', '-i'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
change = p.communicate(changespec)[0]
return change
【问题讨论】:
标签: python python-3.x subprocess perforce changelist