django-wkhtmltopdf icon indicating copy to clipboard operation
django-wkhtmltopdf copied to clipboard

WindowsError [Error 6] The handle is invalid

Open n1b0r opened this issue 9 years ago • 10 comments

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

n1b0r avatar Sep 21 '15 10:09 n1b0r

Find the solution? I have the same problem.

mgarc avatar Feb 02 '16 22:02 mgarc

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)

n1b0r avatar Feb 03 '16 08:02 n1b0r

Thank you, that solve the problem

mgarc avatar Feb 13 '16 00:02 mgarc

@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 ;-)

johnraz avatar Feb 17 '16 20:02 johnraz

Please help me. I have same problem on python 3: https://github.com/incuna/django-wkhtmltopdf/issues/130

SeyfertCode avatar Feb 16 '17 21:02 SeyfertCode

The workaround is described above, we are still waiting for a proper PR

johnraz avatar Feb 16 '17 21:02 johnraz

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

mcramp avatar Jan 12 '18 16:01 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 avatar Jan 14 '18 18:01 mcramp

@mcramp Are you working with virtual environments? why is falling back to Python 2.7? How did you install the Wkhtmltopdf dll?

arag0n avatar Jun 24 '18 20:06 arag0n

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

R2wou avatar Mar 20 '19 12:03 R2wou