# Fix Python os.popen(cmd).read() UnicodeDecodeError: ‘gbk’ codec can’t decode byte

By | April 30, 2020

Python os.popen() can allow us to call other applications by command line (cmd), this function also can return the output of cmd. However, you may find this error when reading the output: UnicodeDecodeError: ‘gbk’ codec can’t decode byte. In this tutorial, we will introduce you how to fix it.

As we know, os.popen() will return a os._wrap_close object, we can read its output by read() function.

Here is an example:

result = os.popen(cmd)
print(msg)