Forums

Weasyprint trying to show an image generates error 504-backend

Hello:

I have a small test application for creating pdf from my webapp. It uses weasyprint and works ok in my local computer, but when i try to run it in production I receive error 504-backend after long time of waiting. Inside the html page there is a picture, it is shown when i see the page on production. When I remove the picture, the weasyprint does its job and shows the document correctly.

How can I solve the problem that Weasyprint would be able to process images inside pythonanywhere.com

I would break your application into two halves. Firstly, a web front end. Secondly, a command line Python app. Have the web front end drop the uploaded file in a directory. Then use the command line app to spot the upload, process it, and then put in a place where the Web app can see it.

Hello thanks for the reply.

My content (image) is static, and it is recognized by the template itself. The problem appears (crashing) when I try to print to PDF with weasyprint, and the image is included.

If the image is removed from the template the PDF is rendered ok but without images.

When you say it is crashing, do you mean it hangs forever or do you mean that it errors? If it errors, what is the error/traceback?

Error message: 504-Backend, happens after several minutes. Not knowing how to trace further in your platform.

Hi there, there's a few tips on 502/504s here -- my guess is yours are due to the request taking too long.

https://help.pythonanywhere.com/pages/502BadGateway

the solution is probably to move the slow code off into some sort of async queue: https://help.pythonanywhere.com/pages/AsyncInWebApps