I have a solution that works in development (VScode, Django v5.1, Python 3.12.5) returning a pdf file created in a buffer using io.BytesIO then return a page response using FileResponse. The following is part of the code that works in the development environment:
buffer = io.BytesIO()
myCanvas = Canvas(buffer, pagesize=letter)
{... more code here to produce the pdf content ... }
myCanvas.showPage()
myCanvas.save()
buffer.seek(0)
return FileResponse(buffer, as_attachment=False, filename="filename.pdf")
Now when I deploy (Ubuntu 22.04 , OpenLiteSpeed 1.7.19, Django 5.1, Python 3.10.12) I get a ‘500 Internal Error’. Looks like all of the generation code works but when returning the resulting buffer in FileResponse() the error occurs. The only error I see in the logs is in the lsws/logs/stderr.log which says ‘io.UnsupportedOperation: fileno’. I'm not sure this is a OpenLiteSpeed issue or a Django issue but any help would be appreciated.
buffer = io.BytesIO()
myCanvas = Canvas(buffer, pagesize=letter)
{... more code here to produce the pdf content ... }
myCanvas.showPage()
myCanvas.save()
buffer.seek(0)
return FileResponse(buffer, as_attachment=False, filename="filename.pdf")
Now when I deploy (Ubuntu 22.04 , OpenLiteSpeed 1.7.19, Django 5.1, Python 3.10.12) I get a ‘500 Internal Error’. Looks like all of the generation code works but when returning the resulting buffer in FileResponse() the error occurs. The only error I see in the logs is in the lsws/logs/stderr.log which says ‘io.UnsupportedOperation: fileno’. I'm not sure this is a OpenLiteSpeed issue or a Django issue but any help would be appreciated.