In Python 3, if you want to read binary data from stdin, you need to use its buffer attribute:
stdin
buffer
import sysdata = sys.stdin.buffer.read()
On Python 2, sys.stdin.read() already returns a byte string; there is no need to use buffer.
sys.stdin.read()