wkhtmltopdf 没有文件/目录错误?

问题描述 投票:0回答:1

我的 htmlt 到 pdf 转换工作正常,直到突然我开始收到以下错误

Traceback (most recent call last):
File "/home/ubuntu/miniconda/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script
exec(code, module.__dict__)
File "/home/ubuntu/Design2/pages/results.py", line 391, in <module>
PDFFile = pdfkit.from_string(html_string,"output.pdf")
File "/home/ubuntu/.local/lib/python3.10/site-packages/pdfkit/api.py", line 75, in from_string
return r.to_pdf(output_path)
File "/home/ubuntu/.local/lib/python3.10/site-packages/pdfkit/pdfkit.py", line 221, in to_pdf
raise IOError('Command failed: %s\n'
OSError: Command failed: /usr/bin/wkhtmltopdf --quiet - output.pdf
Check whhtmltopdf output without 'quiet' option
[Errno 2] No such file or directory: 'output.pdf' 

我的代码如下:

 html_string = "<ul>"
for list in unique_results:
    link = list[0]
    title = list[1]
    companyName = list[2]
    shortSummary = list[3]
    fullDescription = list[4]
    location = list[5]
    skills = list[6]
    html_string += "<li><a href='" + link + "'>" + title + " at " + companyName + "</a><ul><li>" + shortSummary + "</li></ul></li>"
html_string += "</ul>"

# generate the pdf
# PDFFile = pdfkit.from_string(html_string, "19thStreet.pdf")

# config = pdfkit.configuration(wkhtmltopdf=bytes('/var/cache/apt/archives/wkhtmltopdf_0.12.6-2_amd64', 'utf-8'))
PDFFile = pdfkit.from_string(html_string,"output.pdf")

with open("output.pdf", "rb") as pdf_file:
    PDFbyte = pdf_file.read()

有人知道可能出了什么问题吗?

python wkhtmltopdf streamlit pdfkit
1个回答
0
投票

这可能无关紧要,但大约一个月前,当我开始使用最新版本的

wkhtmltopdf
时,我的脚本开始出现问题。我不记得这个错误了,但它是通过使用
wkhtmltopdf --enable-local-file-access
解决的。

© www.soinside.com 2019 - 2024. All rights reserved.