【问题标题】:wkhtmltopdf in python script is not working with cronjobpython脚本中的wkhtmltopdf不适用于cronjob
【发布时间】:2020-04-09 16:32:19
【问题描述】:

在将 python 脚本作为 cronjob 运行时出现以下错误。但它在手动执行时工作。

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/pdfkit/configuration.py", line 21, in __init__
    with open(self.wkhtmltopdf) as f:
FileNotFoundError: [Errno 2] No such file or directory: b''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/aws_security_cost_audit.py", line 626, in <module>
  File "/home/ubuntu/aws_security_cost_audit.py", line 621, in main

  File "/home/ubuntu/aws_security_cost_audit.py", line 95, in html_to_pdf

  File "/usr/local/lib/python3.4/dist-packages/pdfkit/api.py", line 47, in from_file
    configuration=configuration, cover_first=cover_first)
  File "/usr/local/lib/python3.4/dist-packages/pdfkit/pdfkit.py", line 42, in __init__
    self.configuration = (Configuration() if configuration is None
  File "/usr/local/lib/python3.4/dist-packages/pdfkit/configuration.py", line 27, in __init__
    'https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf' % self.wkhtmltopdf)
OSError: No wkhtmltopdf executable found: "b''"
If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf

文件/usr/local/bin/wkhtmltopdf是可执行文件,默认导出路径。

root@jump-box:/home/ubuntu# whereis wkhtmltopdf
wkhtmltopdf: /usr/local/bin/wkhtmltopdf

root@jump-box:/home/ubuntu# which wkhtmltopdf
/usr/local/bin/wkhtmltopdf

root@jump-box:/home/ubuntu# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

你猜猜可能是什么问题?

【问题讨论】:

  • 看起来self.wkhtmltopdf是一个空字节串......现在为什么会这样,应该是什么,没有更多信息我们无法判断。也许minimal reproducible example 可以提供帮助?

标签: python ubuntu cron ubuntu-14.04 wkhtmltopdf


【解决方案1】:

如果我添加这份工作:

 * * * * * echo $PATH >> /ws/tmp.log 2>&1

然后:

> cat tmp.log
/usr/bin:/bin

因此,您可能希望将您的 cronjob 包装在正确设置环境的脚本中

【讨论】:

  • 谢谢@Jonah /usr/local/bin 没有显示 cron。我已经通过在 crontab 中添加 PATH 来修复它。
猜你喜欢
  • 1970-01-01
  • 2015-03-31
  • 2021-01-22
  • 1970-01-01
  • 1970-01-01
  • 2014-08-08
  • 1970-01-01
  • 2019-08-09
  • 1970-01-01
相关资源
最近更新 更多