jabacif.mosequf
jabacif.mosequf

Reputation: 31

Python Flask WkHTMLtoPDF not loading local CSS and files

I am getting the following error, despite adding the appropriate options

rendered= render_template('data.html', data=data)
options = {'enable-local-file-access' : True}
pdf = pdfkit.from_string(rendered,False,configuration=config,options=options)

From what I read I need to give the file access, hence I defined that options to allow local file access. But it still throws a bunch of weird errors

OSError: wkhtmltopdf reported an error:
Loading pages (1/6)
Error: Failed to load file:///static/css/bootstrap.min.css, with network status code 203 and http status code 0 - Error opening /static/css/bootstrap.min.css: The system cannot find the path specified.
Warning: Failed to load file:///static/css/all.css (ignore)
Warning: Failed to load file:///static/css/base.css (ignore)
Error: Failed to load file:///static/js/jquery-3.2.1.slim.min.js, with network status code 203 and http status code 0 - Error opening /static/js/jquery-3.2.1.slim.min.js: The system cannot find the path specified.
Warning: Failed to load file:///static/js/[email protected] (ignore)
Warning: Failed to load file:///static/css/modern.css (ignore)
Error: Failed to load file:///static/js/survey.jquery.min.js, with network status code 203 and http status code 0 - Error opening /static/js/survey.jquery.min.js: The system cannot find the path specified.
Error: Failed to load file:///static/js/jquery-3.6.0.min.js, with network status code 203 and http status code 0 - Error opening /static/js/jquery-3.6.0.min.js: The system cannot find the path specified.
Error: Failed to load file:///static/js/popper.min.js, with network status code 203 and http status code 0 - Error opening /static/js/popper.min.js: The system cannot find the path specified.
Error: Failed to load file:///static/js/bootstrap.min.js, with network status code 203 and http status code 0 - Error opening /static/js/bootstrap.min.js: The system cannot find the path specified.
Warning: Failed to load file:///static/img/logo.png (ignore)
Error: Failed to load http://true/, with network status code 3 and http status code 0 - Host true not found
Error: Failed loading page http://true (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: ContentNotFoundError
192.168.50.219 - - [05/Aug/2021 21:56:12] "GET /responses/2?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
192.168.50.219 - - [05/Aug/2021 21:56:12] "GET /responses/2?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
192.168.50.219 - - [05/Aug/2021 21:56:12] "GET /responses/2?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
192.168.50.219 - - [05/Aug/2021 21:56:12] "GET /responses/2?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1" 200 -
192.168.50.219 - - [05/Aug/2021 21:56:12] "GET /responses/2?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -

Upvotes: 1

Views: 963

Answers (1)

Nori
Nori

Reputation: 2972

ContentNotFoundError seems to occur when another file that is loaded in the file in error cannot be found. An example of this is loading font files.

Bootstrap contains a lot of fonts and they cause errors.

I also don't know how to get all fonts to load correctly.

If you simply read the font with CSS, there is a way to convert it to base64

Upvotes: 0

Related Questions