2016-01-05 7 views
0

Я использую pdfkit для преобразования html-файла в pdf. Пока я работаю на терминале python, он отлично работает и преобразует один и тот же html-файл. Но когда я пытаюсь запустить тот же код из оболочки django, он дает эту ошибку.pdfkit с django дает ошибку Выход с кодом 1 из-за сетевой ошибки: ContentOperationNotPermittedError

Ниже приведен код, указанный:

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)

Он бросает мне под данную ошибку:

*** 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

ответ

0

Когда РУНН Внутри django он считает, что вы используете протокол http:// по умолчанию. Это позволяет добавить http:// в начале каждого пути. И поэтому он предположил, что аргументы являются списками (так как pdfkit принимает списки тоже). Это может быть из-за this, но я не могу сказать точно без дополнительной информации о настройке сервера.

Вы можете попробовать следующее:

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) 

file:// Дополнительные силы Джанго и pdfkit искать внутри вашей файловой системы.

1

Получил решение. Очевидно, pdfkit не смог найти исполняемый файл wkhtmltopdf. Мы должны явно указать путь wkhtmltopdf.

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

0

Не знаю, почему, но положить входной файл в список, кажется, это исправить:

pdfkit.from_file([html_url], pdf_url)