python 脚本中的 wkhtmltopdf 不适用于 cronjob

wkhtmltopdf in python script is not working with cronjob

我在 运行 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

猜猜可能是什么问题?

如果我添加这个工作:

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

然后:

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

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