在docker环境中的wkhtmltopdf中的subprocess错误
当我尝试在Docker环境中运行wkhtmltopdf时,获取下面的错误。
subprocess.CalledProcessError: Command '['wkhtmltopdf', '--encoding', 'utf8', '--margin-top', '10', '--quiet', '/tmp/wkhtmltopdf85qv7fvc.html', '-']' died with <Signals.SIGABRT: 6>.
代码如下所示。
它正在使用Ubuntu 16.04stream浪汉机器。 但是,当我将它移动到docker环境时,它会失败,出现上述错误。 起初,我正在使用Python3.6的图像,然后更改为Ubuntu 16.04的图像,可能wkhtmltopdf需要一个更完善的Linux环境。 但是还是没有运气。
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
问题是wkhtmltopdf
需要DISPLAY
/ Xserver。
使用openlabs/docker-wkhtmltopdf
作为基础映像可以解决您的问题。
- 用Django设置Sentry
- 由Jenkins构build的Django应用程序的Docker容器错误时间
- 服务大型数据集w / Docker,nginx和django
- 泊坞窗图像正在运行,但网页错误 – docker
- 没有名为rest_framework的模块。 Django + Docker
- 在基于Docker容器的架构中使用数据库服务器
- 为什么docker-compose使用〜60GB来构build这个图像
- 使用预configuration的Docker容器进行Elastic Beanstalk Django部署
- 当docker运行时,会发生错误。 “ValueError:无法configuration处理程序”守望台“:您必须指定一个区域。”