TypeError: can't use a string pattern on a bytes-like object TypeError: can't use a string pattern on a bytes-like object python-3.x python-3.x

TypeError: can't use a string pattern on a bytes-like object


If you use Python 3.x, you should pass str object to json.loads.

Replace following line:

print(json.loads(line))

with:

print(json.loads(line.decode()))

UPDATE: The behavior changed in Python 3.6. The argument can now be of type bytes or bytearray. The input encoding should be UTF-8, UTF-16 or UTF-32.