pdfkit.from_url报错

pdfkit.from_url报错

import pdfkit

# pdfkit.from_string pdfkit.from_url  pdfkit.from_file -->html

pdfkit.from_url('https://www.imooc.com','test1.pdf')

按照视频中的代码进行练习,运行后有报错。这个是什么原因。报错内容如下

��Ϣ: ���ṩ��ģʽ�޷��ҵ��ļ���
Traceback (most recent call last):
  File "E:\Part1\Lib\site-packages\pdfkit\configuration.py", line 35, in __init__
    with open(self.wkhtmltopdf) as f:
         ^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: b''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\pythonLearn\Part1\办公自动化\test3.py", line 7, in <module>
    pdfkit.from_url('https://www.imooc.com','test1.pdf')
  File "E:\Part1\Lib\site-packages\pdfkit\api.py", line 24, in from_url
    r = PDFKit(url, 'url', options=options, toc=toc, cover=cover,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Part1\Lib\site-packages\pdfkit\pdfkit.py", line 45, in __init__
    self.configuration = (Configuration() if configuration is None
                          ^^^^^^^^^^^^^^^
  File "E:\Part1\Lib\site-packages\pdfkit\configuration.py", line 38, in __init__
    raise IOError('No wkhtmltopdf executable found: "%s"\n'
OSError: No wkhtmltopdf executable found: "b''"
If this file exists please check that this process can read it or you can pass path to it manually in method call, check README. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf

进程已结束,退出代码为 1

本地环境中已经安装了pdfkit

相关截图:

https://img1.sycdn.imooc.com//climg/64e2158309495da612681399.jpg

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕小猿 2023-08-24 17:58:00

同学,你好!检查一下是否有安装 wkhtmltopdf 依赖包,并且要指定其 configuration 配置,详细步骤参考:https://class.imooc.com/lesson/2102#mid=58018 

祝:学习愉快!


  •  configuration 配置怎么操作,下面的链接不对

    2023-09-27 15:37:20
  • 同学,你好!链接是对的。设置configuration 是指将wkhtmltopdf.exe的所在路径写在pdfkit.configuration函数中,或者将wkhtmltopdf添加到系统环境变量中。两种方法选一种就可以的

    https://img1.sycdn.imooc.com//climg/651550c809e96dd810430804.jpg

    祝学习愉快~



    2023-09-28 18:11:08
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星

相似问题

登录后可查看更多问答,登录/注册

请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师