Abhishek Suran
Abhishek Suran

Reputation: 169

TypeError: a bytes-like object is required, not 'str' in subprocess.check_output

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('=')

Upvotes: 9

Views: 8689

Answers (2)

rokpoto.com
rokpoto.com

Reputation: 10736

Another solution is adding text=True to check_output:

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

Upvotes: 0

Rajez
Rajez

Reputation: 4067

Decode before using split funtion

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

Upvotes: 13

Related Questions