以cronjob身份运行python脚本时,出现以下错误。但是它可以在手动执行时工作。
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
有什么可能的问题吗?
答案 0 :(得分:1)
如果我添加此作业:
* * * * * echo $PATH >> /ws/tmp.log 2>&1
然后:
> cat tmp.log
/usr/bin:/bin
因此,您可能希望将cronjob封装在正确设置环境的脚本中