我正在尝试使用pdfkit
在我的烧瓶应用程序中生成pdf。
在localhost上,应用程序运行正常,没有任何错误,我在ubuntu服务器vps上部署应用程序后,在尝试生成pdf文件时,它在控制台中给出了这个错误:
Apr 12 16:31:51 ubuntu gunicorn[18725]: self.configuration = (Configuration() if configuration is None
Apr 12 16:31:51 ubuntu gunicorn[18725]: File "/home/userp/app/venv/local/lib/python2.7/site-packages/pdfkit/configuration.py", line 18, in
Apr 12 16:31:51 ubuntu gunicorn[18725]: ['which', 'wkhtmltopdf'], stdout=subprocess.PIPE).communicate()[0].strip()
Apr 12 16:31:51 ubuntu gunicorn[18725]: File "/home/userp/app/venv/local/lib/python2.7/site-packages/gevent/subprocess.py", line 585, in __
Apr 12 16:31:51 ubuntu gunicorn[18725]: reraise(*exc_info)
Apr 12 16:31:51 ubuntu gunicorn[18725]: File "/home/userp/app/venv/local/lib/python2.7/site-packages/gevent/subprocess.py", line 554, in __
Apr 12 16:31:51 ubuntu gunicorn[18725]: restore_signals, start_new_session)
Apr 12 16:31:51 ubuntu gunicorn[18725]: File "/home/userp/app/venv/local/lib/python2.7/site-packages/gevent/subprocess.py", line 1312, in _
Apr 12 16:31:51 ubuntu gunicorn[18725]: raise child_exception
Apr 12 16:31:51 ubuntu gunicorn[18725]: OSError: [Errno 2] No such file or directory
如果我尝试打印self.wkhtmltopdf
的值,则在 configuration.py 文件下方显示文件路径 / usr / bin / wkhtmltopdf :
if not self.wkhtmltopdf:
if sys.platform == 'win32':
self.wkhtmltopdf = subprocess.Popen(
['where', 'wkhtmltopdf'], stdout=subprocess.PIPE).communicate()[0].strip()
else:
self.wkhtmltopdf = subprocess.Popen(
['which', 'wkhtmltopdf'], stdout=subprocess.PIPE).communicate()[0].strip()
try:
with open(self.wkhtmltopdf) as f:
pass
except IOError:
raise IOError('No wkhtmltopdf executable found: "%s"\n'
'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' % self.wkhtmltopdf)
同时输入which wkhtmltopdf
会得到相同的结果,这意味着该程序已经安装。
我已经在我的机器上安装了所有必需的库。
最有趣的是,如果我从python manage.py runserver
运行应用程序并尝试生成pdf文件,它会生成并且不会出现任何错误,但是从gunicorn和nginx出现错误!!!!! < / p>
我已经尝试了所有工作,我也看过很多文章,他们在谈论这个问题,但没有用!!!!
答案 0 :(得分:0)
问题很可能是无法在服务器vps中以无头状态运行wkhtmltopdf。
请查看https://pypi.org/project/headless-pdfkit/0.1.1/#files
这还需要安装xvfb,它会在执行之前使用/ bin / bash \ nxvfb-run包装wkhtmltopdf命令。