Hyun-geun Kim Hyun-geun Kim - 2 years ago 283
Python Question

python - convert binary data to utf-8

_f = open("c:/go-next.png", "rb")
data = _f.read()

# Error: UnicodeDecodeError: file <maya console> line 1: ascii #

As you see I open a image file, and the data is type. But I have to convert it to utf-8.
Maybe binary data has some extra char (or not), it conflict with conversion. Is there any way to solve it?

Answer Source

Text encodings only apply to text. Do not attempt to use them on binary data.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download