2016-01-05 128 views
0

我正在使用pdfkit將html文件轉換爲pdf。雖然我運行在python終端,它工作正常,並轉換相同的HTML文件。但是當我嘗試從django shell運行相同的代碼時,它會出現此錯誤。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

的Runn當在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://軍隊Django和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)