TypeError:需要一个类似字节的对象,而不是 subprocess.check_output 中的“str"

2022-01-18 00:00:00 python python-3.x subprocess

问题描述

我得到 TypeError: a bytes-like object is required, not 'str' in the following line code in python3.5.

I am getting TypeError: a bytes-like object is required, not 'str' in the following line of code in python3.5.

path = os.getcwd().strip('/n')
Null,userprof = subprocess.check_output('set USERPROFILE', shell=True).split('=')


解决方案

使用split功能前解码

Null,userprof = subprocess.check_output('set USERPROFILE', shell=True).decode('utf-8').split('=')

相关文章