我正在尝试用pdfkit在我的烧瓶应用程序中生成一个pdf。
在本地主机上,应用程序工作正常,没有任何错误,在我将应用程序部署在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在下面的configuration.py文件中,如果我试图打印出self.wkhtmltopdf的值,它将显示文件路径/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文件,它的get生成并且没有出现错误,但是从gunicorn和nginx就会出现错误!
我已经尽了一切努力,我也看到了很多文章,他们谈论这个问题,但没有用!
发布于 2018-04-30 13:43:45
问题很可能是无法在服务器vps中以无头状态运行wkhtmltopdf。
请看一下https://pypi.org/project/headless-pdfkit/0.1.1/#files
这还需要安装xvfb,它将在执行之前使用/bin/bash\nxvfb-运行wkhtmltopdf命令。
https://stackoverflow.com/questions/49794491
复制相似问题