I encounter the same problem. Maybe it has been solved for you since the quetion has been past so long time.
In my problem, I open the file with 'rb' mode, and read() method for file handler will return <type 'bytes'>, so jinja2 Template.render() will also return a string wrapper of string. (Just something you call it bytes with prefix 'b' and quotes)
with open("file.txt", "rb") as f: text = f.read() # type(text) -> <class 'bytes'> template = Template(f.read()) template.render(kwargs)
After I modify the open mode with 'r', this time everything works as expected.
with open("file.txt", "r") as f: text = f.read() # type(text) -> <class 'str'> template = Template(text) template.render(kwargs)
So the problem is the type of real parameter in Template constructor function.