question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"You will need to run whktmltopdf within a "virutal" X server" error when being executed within crontab job

See original GitHub issue

I am getting an exception when my script is being executed by crontab job:

You will need to run whktmltopdf within a "virutal" X server.
Go to the link above for more information
https://github.com/JazzCore/python-pdfkit/wiki/Using-wkhtmltopdf-without-X-serverUse exit() or Ctrl-D (i.e. EOF) to exit

If I run the script manually - it works and saves html to pdf. So of course I did that magic which is written in the URL above. But it doesn’t help when script is executed within crontab (root user)

Debian 7

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
svscorpcommented, Jan 23, 2015

Some investigation:

  1. I checked the arguments PDFKit is calling wkhtmltopdf with that way (from string, btw, that’s why 3rd argument is ‘-’):
['/usr/bin/wkhtmltopdf', '--quiet', '-', '497479169.pdf']
  1. With https://github.com/JazzCore/python-pdfkit/wiki/Using-wkhtmltopdf-without-X-server We are making the shortcut in /usr/bin/wkhtmltopdf.sh and then the symlink here: ln -s /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf
  2. When cron is executing the python script, even a simple one
#!/usr/bin/python3

import pdfkit

options = {
    'quiet': ''
}

print('start')
pdfkit.from_url('http://google.com', '/tmp/google.pdf', options=options)
print('stop')

PDFKit is calling /usr/bin/wkhtmltopdf when is being executed from CRON. When it is executed from command line it uses our shortcut /usr/local/bin/wkhtmltopdf

0reactions
JazzCorecommented, Mar 19, 2021

Should be fixed now, closing

Read more comments on GitHub >

github_iconTop Results From Across the Web

can't run wkhtmltopdf from a cronjob - Stack Overflow
The cronjob may not be pulling in the environment of the user and therefor doesn't know what $PATH actually contains. I've found I...
Read more >
Since xorg 1.20, can no longer change root window from cron job
I have a cron job that every three minutes runs a shell script, that will recurse ... specially for cases like this (it...
Read more >
Unable to execute a python script via crontab ... - DigitalOcean
In summary: My script works without error when manually executed, but for some reason the cron job is either not executing it, or...
Read more >
8.3. Web config file — CRATE 0.19.4 documentation
Defaults are in crate_anon.crateweb.config.settings , which are then overridden as ... Overriding BROKER_URL will allow you to use multiple virtual hosts, ...
Read more >
Nagios XI Change Log
Nagios XI provides network, server, and application monitoring. ... Fixed issue with Availability report rounding/data error in service averages in the data ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found