From 4b73d48254749bbf08c42126f10b16ac2d71f004 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 28 Jul 2015 18:36:08 -0700 Subject: Patch python3 / mod_wsgi incompatibility on sys.stderrr.fileno() call Root cause of this issue is in python3 / mod_wsgi. See: https://github.com/GrahamDumpleton/mod_wsgi/issues/85 This patch detects if there is something screwy with fileno() and simply skips setting stderr if there is to avoid the AttributeError that occurs otherwise. Pull https://github.com/incuna/django-wkhtmltopdf/pull/40 fixed this same issue when it arose for python 2.7, but the nature of the issue seems to have shifted, making it trickier to detect that the fileno() method cannot be called. --- wkhtmltopdf/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'wkhtmltopdf') diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index e841380..9c338bf 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -93,8 +93,13 @@ def wkhtmltopdf(pages, output=None, **kwargs): list(pages), [output])) ck_kwargs = {'env': env} - if hasattr(sys.stderr, 'fileno'): + try: + i = sys.stderr.fileno() ck_kwargs['stderr'] = sys.stderr + except AttributeError: + # can't call fileno() on mod_wsgi stderr object + pass + return check_output(ck_args, **ck_kwargs) -- cgit v1.2.3