Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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('=')
like image 917
Abhishek Suran Avatar asked Aug 31 '17 14:08

Abhishek Suran


People also ask

How to fix a bytes like object is required not str?

It means that all data read from the file is returned as bytes objects, not str. We can solve this error by opening the file in read-only mode instead of binary mode, as shown below.

What is subprocess Check_output in Python?

The subprocess. check_output() is used to get the output of the calling program in python. It has 5 arguments; args, stdin, stderr, shell, universal_newlines. The args argument holds the commands that are to be passed as a string.

What is a bytes like object in python?

Bytes-like object in python In Python, a string object is a series of characters that make a string. In the same manner, a byte object is a sequence of bits/bytes that represent data. Strings are human-readable while bytes are computer-readable. Data is converted into byte form before it is stored on a computer.


1 Answers

Decode before using split funtion

Null,userprof = subprocess.check_output('set USERPROFILE', shell=True).decode('utf-8').split('=')
like image 74
Rajez Avatar answered Oct 05 '22 20:10

Rajez