我在uwsgi环境下得到一个CalledProcessError,而我可以在django normal runserver-mode中运行它,并且可以直接在命令行中正确运行该命令。这是我的环境: 环境:
Request Method: GET
Request URL: http://x/api/sheet/?order=1784285260
Django Version: 2.0.1
Python Version: 3.6.3
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'wkhtmltopdf',
'rest_framework',
'django_crontab',
'backend',
'api',
'website']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
回溯:
File "/www/env/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)
File "/www/env/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
158. response = self.process_exception_by_middleware(e, request)
File "/www/env/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
156. response = response.render()
File "/www/env/local/lib/python3.6/site-packages/django/template/response.py" in render
106. self.content = self.rendered_content
File "/www/env/local/lib/python3.6/site-packages/wkhtmltopdf/views.py" in rendered_content
78. cmd_options=cmd_options
File "/www/env/local/lib/python3.6/site-packages/wkhtmltopdf/utils.py" in render_pdf_from_template
186. cmd_options=cmd_options)
File "/www/env/local/lib/python3.6/site-packages/wkhtmltopdf/utils.py" in convert_to_pdf
124. return wkhtmltopdf(pages=filename, **cmd_options)
File "/www/env/local/lib/python3.6/site-packages/wkhtmltopdf/utils.py" in wkhtmltopdf
110. return check_output(ck_args, **ck_kwargs)
File "/usr/lib/python3.6/subprocess.py" in check_output
336. **kwargs).stdout
File "/usr/lib/python3.6/subprocess.py" in run
418. output=stdout, stderr=stderr)
Exception Type: CalledProcessError at /api/sheet/
Exception Value: Command '['/usr/local/bin/wkhtmltopdf.sh', '--dpi', '300', '--encoding', 'utf-8', '--margin-left', '20', '--margin-top', '10', '--orientation', 'Landscape', '--page-size', 'A4', '--print-media-type', '--quiet', '--zoom', '0.88', '/tmp/wkhtmltopdf0fjtzvle.html', '-']' returned non-zero exit status 126.
和我的uwsgi配置:
[uwsgi]
vhost = true
plugin = python36
socket = /tmp/site.sock
master = true
enable-threads = true
processes = 4
virtualenv = /www/env/
home = /www/env
chdir = /www/site/
module = site.wsgi
chomod-socket = 664
uid = www-data
gid = www-data
wkhtmltopdf.sh:
#!/bin/bash
/usr/bin/xvfb-run -a -s "-screen 0 640x480x16"
/root/wkhtmltox/bin/wkhtmltopdf "$@"
我已经将wkhtmltopdf列为www-data:www-data,这仍然无法正常工作,我不知道它是否与特权有关。 而我的wkhtmltopdf版本是wkhtmltopdf 0.12.4(有补丁的qt),我试图从wkhtmltopdf得到stderr输出,但我只能得到stdout