[英]Subprocess error in wkhtmltopdf in a docker environment
Getting the error below when I try to run wkhtmltopdf in a docker environment. 当我尝试在docker环境中运行wkhtmltopdf时出现以下错误。
subprocess.CalledProcessError: Command '['wkhtmltopdf', '--encoding', 'utf8', '--margin-top', '10', '--quiet', '/tmp/wkhtmltopdf85qv7fvc.html', '-']' died with <Signals.SIGABRT: 6>.
The code is seen below. 该代码如下所示。
It is working in an Ubuntu 16.04 vagrant machine. 它正在Ubuntu 16.04流浪者机器中工作。 However, when I move it to a docker environment, it fails with the error above.
但是,当我将其移至docker环境时,它会因上述错误而失败。 At first I was using a Python3.6 image then changed to an Ubuntu 16.04 image thinking that maybe wkhtmltopdf requires a fuller linux environment.
最初,我使用的是Python3.6映像,然后更改为Ubuntu 16.04映像,以为wkhtmltopdf可能需要更完整的linux环境。 But still no luck.
但是仍然没有运气。
from django.http import HttpRequest
from wkhtmltopdf.views import PDFTemplateResponse
def generate_invoice_pdf(download_pdf=False, **kwargs):
"""
Render html to PDF
"""
file_name = kwargs['file_name']
template = kwargs['template']
context = {
"first_Name": "John",
"last_name": "Doe"
}
# Create request object
request = HttpRequest()
params = {
'request': request,
'template': template,
'filename': os.path.basename(file_name),
'context': context,
'cmd_options': {'margin-top': 10, },
'show_content_in_browser': True
}
response = PDFTemplateResponse(**params)
# write the rendered content to a file
with open(file_name, "wb") as f:
f.write(response.rendered_content) # Part throwing the error
if download_pdf:
return response
else:
msg = 'PDF Generated: {}'.format(file_name)
return msg
The problem is that wkhtmltopdf
requires a DISPLAY
/ Xserver. 问题是
wkhtmltopdf
需要DISPLAY
/ Xserver。
Using openlabs/docker-wkhtmltopdf
as a base image could solve your problem. 使用
openlabs/docker-wkhtmltopdf
作为基本图像可以解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.