You have a couple of problems.
You are creating a StringIO , but you are not using it. Your xlsxwriter.Workbook(
should be using output
not self.response.out
Secondly why are you doing output.seek(0)
After closing with workbook, you should be getting the string from output
and writing that out to self.response
And lastly if you are getting an error, it's always useful when asking a question to add the stacktrace to the question. That way we can see which statement in your code is actually causing the exception to be raised.