ypeError: memoryview: a bytes-like object is required, not 'str'

问题遇到的现象和发生背景

TypeError: memoryview: a bytes-like object is required, not 'str'

用代码块功能插入代码,请勿粘贴截图
def RunProc(*args, **kwargs):
    stdin = kwargs.pop("stdin", "")
    p = subprocess.Popen(args, stdout = subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)

    stdout, stderr = p.communicate(stdin)

    if p.returncode == 0:
        if stderr:
            sys.stderr.write(stderr.decode())
        return stdout
    else:
        sys.stderr.write(stderr.decode())
        sys.stdout.write(stdout.decode())
        sys.exit(1)
运行结果及报错内容

stdout, stderr = p.communicate(stdin)
TypeError: memoryview: a bytes-like object is required, not 'str'

File "/Users/ans/opt/anaconda3/lib/python3.9/subprocess.py", line 1134, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "/Users/ans/opt/anaconda3/lib/python3.9/subprocess.py", line 1959, in _communicate
input_view = memoryview(self._input)

stdout, stderr = p.communicate(stdin)

改为

stdout, stderr = p.communicate(stdin.encode())

你这不和前面的问题正好反着了
前面是decode,反过来是encode了

stdout, stderr = p.communicate(stdin.encode())