Skip to content
Advertisement

Return PDF in Azure Function via HttpResponse (PyPDF2)

I created an Azure Function that writes user data into specific fields of a pdf and returns that pdf as a response to the client. However, I always get a 500 error code, even though all the steps up until the last seem to work just fine and it also runs locally without issue.

Here’s my init.py:

JavaScript

I can return things like str(writer.getPage(0)) instead of writer so I assume my requirements.txt works fine. It only fails when returning the HttpResponse without a body of type string. I thought adding the correct mime-type would solve the problem but it returns the same status code. I’m kind of clueless at this point.

Advertisement

Answer

Try creating a bytes object to return:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement