kaushikdr
kaushikdr

Reputation: 2049

pdfkit with django gives error Exit with code 1 due to network error: ContentOperationNotPermittedError

I am using pdfkit to convert an html file to pdf. While I run in python terminal it works fine and converts the same html file. But when I try to run the same code from django shell it gives this error.

Below is the code given:

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

It throws me the below given error:

*** IOError: wkhtmltopdf reported an error:
Loading pages (1/6)
Error: Failed loading page file:/// (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page file:/// (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://u (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://e (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://s (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://r (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://s (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://s (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://w (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://a (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://r (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://n (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page file:/// (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://a (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://w (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://o (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://r (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://k (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://s (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://p (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://a (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page file:/// (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://c (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://e (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://s (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://e (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://r (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://v (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://e (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page file:/// (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://r (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://2 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://0 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://1 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://6 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://0 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://1 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://0 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page file:/// (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://5 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://r (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://e (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://t (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://_ (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://4 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://7 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://4 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://0 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://1 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://0 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://0 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://1 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://0 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://6 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://3 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page file:///Users/swarna/workspace/server/server_codes (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://6 (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://h (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://t (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://m (sometimes it will work just to ignore this error with --load-error-handling ignore)
Error: Failed loading page http://l (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: ContentOperationNotPermittedError

Upvotes: 0

Views: 3449

Answers (3)

Nezo
Nezo

Reputation: 312

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

pdfkit.from_file([html_url], pdf_url)

Upvotes: 0

kaushikdr
kaushikdr

Reputation: 2049

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)

Upvotes: 1

AbdealiLoKo
AbdealiLoKo

Reputation: 3357

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.

Upvotes: 0

Related Questions