waldur / waldur-mastermind

Waldur MasterMind is a hybrid cloud orchestrator.
https://waldur.com
MIT License
48 stars 42 forks source link

Unable to create order PDF #9

Closed stackexpress-jawed closed 4 years ago

stackexpress-jawed commented 4 years ago

Issue description

Hello @AmbientLighter ,

On a headless server this happenes:

OS info:
Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic

Errors


[2020-02-04 09:32:53,450: ERROR/ForkPoolWorker-2] Task waldur_mastermind.marketplace.tasks.create_order_pdf[ad8bad1c-e41c-4872-9801-8228a062f753] raised unexpected: OSError('wkhtmltopdf exited with non-zero code 1. error:\nqt.qpa.screen: QXcbConnection: Could not connect to display \nCould not connect to any X display.\n',)
Traceback (most recent call last):
  File "~/waldur-mastermind/venv/lib/python3.6/site-packages/celery/app/trace.py", line 385, in trace_task
    R = retval = fun(*args, **kwargs)
  File "~/waldur-mastermind/venv/lib/python3.6/site-packages/celery/app/trace.py", line 648, in __protected_call__
    return self.run(*args, **kwargs)
  File "~/waldur-mastermind/src/waldur_mastermind/marketplace/tasks.py", line 74, in create_order_pdf
    utils.create_order_pdf(order)
  File "~/waldur-mastermind/src/waldur_mastermind/marketplace/utils.py", line 112, in create_order_pdf
    pdf = pdfkit.from_string(html, False)
  File "~/waldur-mastermind/venv/lib/python3.6/site-packages/pdfkit/api.py", line 72, in from_string
    return r.to_pdf(output_path)
  File "~/waldur-mastermind/venv/lib/python3.6/site-packages/pdfkit/pdfkit.py", line 159, in to_pdf
    raise IOError("wkhtmltopdf exited with non-zero code {0}. error:\n{1}".format(exit_code, stderr))
OSError: wkhtmltopdf exited with non-zero code 1. error:
qt.qpa.screen: QXcbConnection: Could not connect to display
Could not connect to any X display.

Steps to reproduce the issue

  1. Setup waldur-mastermind on any headless server
  2. And try to buy any available service, you will get the above errors

How to fix this?

You can use Python xvfbwrapper

Basic usage


from xvfbwrapper import Xvfb

vdisplay = Xvfb()
vdisplay.start()

# launch stuff inside
# virtual display here.

vdisplay.stop()

Usage as a Context Manager:


from xvfbwrapper import Xvfb

with Xvfb() as xvfb:
    # launch stuff inside virtual display here.
    # It starts/stops around this code block.

Or you can use alternative of pdfkit named weasyprint

AmbientLighter commented 4 years ago

Hi @stackexpress-jawed! Thank you for the bug report. Could you please specify which release of wkhtmltopdf do you use?

stackexpress-jawed commented 4 years ago

here is package details

dpkg-query -s wkhtmltopdf
Package: wkhtmltopdf
Status: install ok installed
Priority: optional
Section: utils
Installed-Size: 951
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Version: 0.12.4-1
Depends: libc6 (>= 2.14), libgcc1 (>= 1:3.0), libqt5core5a (>= 5.9.0~beta), libqt5gui5 (>= 5.2.0), libqt5network5 (>= 5.0.2), libqt5printsupport5 (>= 5.2.0), libqt5svg5 (>= 5.6.0~beta), libqt5webkit5 (>= 5.6.0~rc), libqt5widgets5 (>= 5.0.2), libstdc++6 (>= 5)
Recommends: xserver | xvfb
....
AmbientLighter commented 4 years ago

Could you please remove wkhtmltopdf installed from ubuntu repository and instead install latest release from official site and check if issue persists?

https://wkhtmltopdf.org/downloads.html

apt remove wkhtmltopdf

wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb

apt-get install -f ./wkhtmltox_0.12.5-1.bionic_amd64.deb