explicitly convert mime_type to a string

mime_type can be unicode on some systems which can cause UnicodeDecodeError
raised from the subsequent str.join()