Fix ensure_stream_with_encoder with six for py3