pdfkit [WinError 740] The requested operation requires elevation python3
Asked Answered
B

3

1

I would like to convert an HTML page into a PDF file, based on the given URL. I have tried pdfkit, but it throws the following error:

[WinError 740] The requested operation requires elevation.

Code:

import pdfkit
path_wkthmltopdf = "D:\\w.exe"
config = pdfkit.configuration(wkhtmltopdf = path_wkthmltopdf )
pdfkit.from_url("http://www.google.com", 'd:\\out.pdf', configuration=config)

Output error:

n [42]: import pdfkit
path_wkthmltopdf = "D:\\w.exe"
config = pdfkit.configuration(wkhtmltopdf = path_wkthmltopdf )

pdfkit.from_url("http://www.google.com", 'd:\\out.pdf', configuration=config)
Traceback (most recent call last):

  File "<ipython-input-42-58323936ac63>", line 5, in <module>
    pdfkit.from_url("http://www.google.com", 'd:\\out.pdf', configuration=config)

  File "C:\Users\31081\AppData\Local\conda\conda\envs\ml\lib\site-packages\pdfkit\api.py", line 26, in from_url
    return r.to_pdf(output_path)

  File "C:\Users\31081\AppData\Local\conda\conda\envs\ml\lib\site-packages\pdfkit\pdfkit.py", line 129, in to_pdf
    stderr=subprocess.PIPE)

  File "C:\Users\31081\AppData\Local\conda\conda\envs\ml\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 143, in __init__
    super(SubprocessPopen, self).__init__(*args, **kwargs)

  File "C:\Users\31081\AppData\Local\conda\conda\envs\ml\lib\subprocess.py", line 729, in __init__
    restore_signals, start_new_session)

  File "C:\Users\31081\AppData\Local\conda\conda\envs\ml\lib\subprocess.py", line 1017, in _execute_child
    startupinfo)

OSError: [WinError 740] The requested operation requires elevation
Bobo answered 8/1, 2020 at 8:13 Comment(1)
Hey @Abhishek, did you ever solve this problem. I'm encountering the sameDufrene
S
2

I encountered with this problem too, I solved it by running .exe after run this it will create new dir, go inside this dir then bin dir you will find a exe file there like C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe So, replace "D:\w.exe" to above kind of path in your code then it will work

Solmization answered 20/1, 2021 at 15:42 Comment(0)
E
0

Cause

You are most likely getting that error as a result of downloading the Installer version, but not installig it. Thus, when running your code with wkhtmltopdf in the configuration pointing to that executable (which requires elevation of privilege), you get the following error:

OSError: [WinError 740] The requested operation requires elevation

Solution

You could install wkhtmltopdf by running that Installer version and choosing the destination folder (let's say C:\Program Files). You will find the wkhtmltopdf.exe file that you need to add to your configuration inside the bin folder. Hence, you should use as follows:

config = pdfkit.configuration(wkhtmltopdf=r'C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe')
pdfkit.from_url('http://google.com', 'out.pdf', configuration=config)

Another solution would be to download the 7z Archive version, extract the files, in which you'll find wkhtmltopdf.exe under the bin folder as well.

Elevated answered 3/4, 2022 at 16:59 Comment(0)
E
-1

I ran into this issue when I had not gone through the full installation of the wkpdftohtml library. Once it was unpacked, this ran without need for elevation.

Exoergic answered 11/12, 2020 at 0:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.