[Fixed]-Pdfkit with django gives error Exit with code 1 due to network error: ContentOperationNotPermittedError

1👍

Got the solution. Apparently pdfkit was unable to find the wkhtmltopdf executable. We have to explicitly mention wkhtmltopdf’s path.

config = pdfkit.configuration(wkhtmltopdf='/usr/local/bin/wkhtmltopdf')
pdfkit.from_file(html_url,pdf_url, configuration=config)

0👍

When running inside django it thinks you’re using the http:// protocol by default. This makes it add a http:// at the beginning of every path. And so it assumed the arguments are lists (as pdfkit accepts lists too). This could be because of this but i can’t say for sure without more details about the server setup.

You could try the following:

html_url = "file:///Users/swarna/workspace/server/"+todays_date+"/ret_"+packages['wbn']+".html"
pdf_url = "file:///Users/swarna/workspace/server/"+todays_date+"/retpdf_"+packages['wbn']+".pdf"
pdfkit.from_file(html_url,pdf_url)

The extra file:// forces django and pdfkit to search inside your filesystem.

0👍

Not sure why, but putting input file into a list seems to fix it:

pdfkit.from_file([html_url], pdf_url)
👤Nezo

Leave a comment