I have code that expects str but will handle the case of being passed bytes in the following way:
str
bytes
if isinstance(data, bytes): data
>>> content = b"hello" >>> text = "hello" >>> type(content) >>> type(text) >>> type(text) is str True >>> type(content) is bytes True