Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wkhtmltoimage --load-error-handling option incorrect handling #43

Open
buffer opened this issue Jun 12, 2020 · 0 comments
Open

wkhtmltoimage --load-error-handling option incorrect handling #43

buffer opened this issue Jun 12, 2020 · 0 comments

Comments

@buffer
Copy link

buffer commented Jun 12, 2020

I think I spotted an issue that prevents the option wkhtmltoimage --load-error-handling to be properly handled by imgkit.

The issue happens here https://github.com/jarrekk/imgkit/blob/master/imgkit/imgkit.py#L239

    if 'Error' in stderr:
        raise IOError('wkhtmltoimage reported an error:\n' + stderr)

Running the last version of wkhtmltoimage (which disables local files loading by default) I see

~$ wkhtmltoimage index.html test.jpg
Loading page (1/2)
Error: Failed loading page file:///home/angelo/index.html (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1, due to unknown error.

~$ wkhtmltoimage --load-error-handling ignore index.html test.jpg
Loading page (1/2)
Warning: Failed loading page file:///home/angelo/index.html (ignored)
Rendering (2/2)
Done

>>> options['load-error-handling'] = 'ignore'
>>> imgkit.from_string(html, 'foobar.jpg', options = options)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/imgkit/api.py", line 90, in from_string
    return rtn.to_img(output_path)
  File "/usr/local/lib/python3.6/dist-packages/imgkit/imgkit.py", line 240, in to_img
    raise IOError('wkhtmltoimage reported an error:\n' + stderr)
OSError: wkhtmltoimage reported an error:
Loading page (1/2)
Warning: Blocked access to file
Error: Failed to load about:blank, with network status code 301 and http status code 0 - Protocol "about" is unknown
Rendering (2/2)
Done
Exit with code 1 due to network error: ProtocolUnknownError

As you can see imgkit detects the Error string in stderr and raises IOError. This is not correct and line 239 should be modified to something like this (abort is the default option while the other ones are ignore and skip)

    load_error_handling_option = self.options.get('--load-error-handling', 'abort')
    if 'Error' in stderr and load_error_handling_option in ('abort', ):
        raise IOError('wkhtmltoimage reported an error:\n' + stderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant