Forums

wkhtmltopdf throws QXcbConnection error

Hi there! I'm facing a "Could not connect to display" error when try to generate a PDF file using a PDFKit in a django app's endpoint. I found out this may be caused by disabled feature for my account (https://eu.pythonanywhere.com/forums/topic/53/). May I ask you to enable it for me?

regards!

Sure! That's done now and will be enabled in any new consoles you start; your website will pick it up the next time it's reloaded.

If you still get the same error, you may be able to work around it by importing PyVirtualDisplay:

from pyvirtualdisplay import Display

...and then wrapping your PDF-generation code in a with statement like this:

with Display():
    # wkhtmltopdf code goes here

Well, the pyvirtualdisplay usage is required to work around the error, the document is generated almost properly, but it looks like not every CSS styles are applied on it. I checked out the version on my local machine (it's 0.12.5) and it differ with the one on PA instance (0.12.2.4). Is there any chance you will upgrade the package in the near future?

regards!

If you have CSS styles that are not applied, perhaps the CSS files are not available to your code on PythonAnywhere.

We have plans to provide an updated wkhtmltopdf, but we do not have an estimate on when that will be available.

No it's not that. All the styles are defined in HTML file directly and it works just fine with the newer version of wkhtmltopdf. I need to find another way as it's a critical feature, but thank you a lot anyway :)

I've made a note to post here when the newer wkhtmltopdf is available -- although, as @glenn says, we don't have a timeline right now, at least you'll know when it's ready.

Thank you once again. Have a good day!

Hello, may I ask you to enable this feature also for this account?

Sure, we have enabled that virtualization feature for you.

Thank you

We've upgraded wkhtmltopdf to 0.12.5 on the glastonbury system image. If you need this version, upgrade your system image, following steps mentioned here: https://help.pythonanywhere.com/pages/ChangingSystemImage/.

Thanks for an update

Our pleasure

Hi, could you enable the virtualization also for me?

It's enabled for everyone.