django-wkhtmltopdf
django-wkhtmltopdf copied to clipboard
WindowsError [Error 6] The handle is invalid
Hello,
My django project include the 'wkhtmltopdf' app. Everything works fine on Ubuntu.
When deploying on windows server 2008 R2 I get the following error :
WindowsError [Error 6] The handle is invalid
Does anyone already face this issue ? How to get django-wkhtmltopdf working on windows ?
Thanks nib
Find the solution? I have the same problem.
hello,
As far as I remember, I updated the check_output
method in the file subprocess.py:
I replaced :
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it will be overridden.')
process = Popen(stdout=PIPE, *popenargs, **kwargs)
by
if 'stdout' in kwargs:
raise ValueError('stdout argument not allowed, it will be overridden.')
kwargs.pop('stderr', None)
process = Popen(stdout=PIPE, stderr=PIPE, stdin=PIPE, *popenargs, **kwargs)
Thank you, that solve the problem
@n1b0r could you explain how you came up with that solution and maybe submit a PR with your fix? I don't have the time to dig this right now, just want to push the library a bit further towards compatibility ;-)
Please help me. I have same problem on python 3: https://github.com/incuna/django-wkhtmltopdf/issues/130
The workaround is described above, we are still waiting for a proper PR
I am trying to run Django wkhtmltopdf on an azure web app. I have tried the above solution by editing the check_output method in the wkhtmltopdf app, but still seem to be having this issues. The code runs okay on my local machine but when I load it on the server I get the WindowsError [Error 6] The handle is invalid
I'm using Django 1.11.6 Django-Wkhtmltopdf 3.1.0 Azure App with 3.6.1 enviroment
Thanks in advance,
mcramp
Think I have a little fix for the above. It appears that for 3+ versions of python there is a change in the standard subprocess.py method. If you delete the import from the subprocess.py in the fiile in the wkhtmltopdf app then it will force it to use the 2.7 method and will generate the PDF.
@mcramp Are you working with virtual environments? why is falling back to Python 2.7? How did you install the Wkhtmltopdf dll?
For Pyhton 3+ on IIS one has to edit the wkhtmltopdf's utils.py-file:
Change:
from .subprocess import check_output
To:
from .subprocess import check_output, PIPE
and add in the wkhtmltopdf()
-function
if not ck_kwargs.get('stderr'):
ck_kwargs['stderr'] = PIPE
right before
return check_output(ck_args, **ck_kwargs)
I accidently gave myself a 'thumbs up'... blush