[英]Pdfkit/wkhtmltopdf - OSError: [Errno 8] Exec format error
請查看下面的錯誤跟蹤。
In [1]: import pdfkit In [2]: pdfkit.from_string('a', 'a.pdf') --------------------------------------------------------------------------- OSError Traceback (most recent call last) in () ----> 1 pdfkit.from_string('a', 'a.pdf') /root/.virtualenvs/v1/lib/python2.7/site-packages/pdfkit/api.pyc in from_string(input, output_path, options, toc, cover, css, configuration) 66 configuration=configuration) 67 ---> 68 return r.to_pdf(output_path) 69 70 /root/.virtualenvs/v1/lib/python2.7/site-packages/pdfkit/pdfkit.pyc in to_pdf(self, path) 91 92 result = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, ---> 93 stderr=subprocess.PIPE) 94 95 # If the source is a string then we will pipe it into wkhtmltopdf. /usr/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags) 708 p2cread, p2cwrite, 709 c2pread, c2pwrite, --> 710 errread, errwrite) 711 except Exception: 712 # Preserve original exception in case os.close raises. /usr/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite) 1325 raise 1326 child_exception = pickle.loads(data) -> 1327 raise child_exception 1328 1329 OSError: [Errno 8] Exec format error
我不確定這是問題還是某些故障,它在我的本地系統中工作(安裝很久),但在Digital Ocean Server中卻不工作。 兩者都是Ubuntu 14。
我按照此頁面上的說明進行操作-http://fedir.github.io/web/blog/2013/09/25/install-wkhtmltopdf-on-ubuntu/
請注意,我能夠使用終端命令生成pdf,但無法使用pdfkit。
如果我錯過了任何事情,請告訴我。
更新-此鏈接的解決方案對我有用。
正如@ user1305989的評論,以下是解決方案,
腳步:
首先安裝xvfb服務器:
sudo apt-get install xvfb
從http://wkhtmltopdf.org/downloads.html獲取所需的wkhtmltopdf版本。
對於Ubuntu 14.04 64位:
wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-trusty-amd64.deb
安裝wkhtmltopdf:
sudo dpkg -i wkhtmltox-0.12.2.1_linux-trusty-amd64.deb
安裝依賴項(如果需要):
sudo apt-get -f install
在/usr/local/bin/
創建符號鏈接:
echo 'exec xvfb-run -a -s "-screen 0 640x480x16" wkhtmltopdf "$@"' | sudo tee /usr/local/bin/wkhtmltopdf.sh >/dev/null sudo chmod a+x /usr/local/bin/wkhtmltopdf.sh
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.