How to get binary data from Python’s ByteIO

Use the getvalue() function of the BytesIO instance. Example:

#!/usr/bin/env python3
from io import BytesIO

myio = BytesIO()
myio.write(b"Test 123")

print(myio.getvalue()) # Prints b'Test 123'