WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed.

Bug #1850835 reported by Petr Vorel
34
This bug affects 7 people
Affects Status Importance Assigned to Milestone
calibre
Invalid
Undecided
Unassigned

Bug Description

Coversion to pdf fails with "WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed."

Is it an installation problem?

$ ebook-convert gook.epub book.pdf
1% Converting input to HTML...
InputFormatPlugin: EPUB Input running
on /tmp/download/im-lichte-der-wahrheit-gralsbotschaft-band-1-2-3_1.epub
Parsing all content...
34% Running transforms on e-book...
Merging user specified metadata...
Detecting structure...
Flattening CSS and remapping font sizes...
Source base font size is 12.00000pt
Removing fake margins...
Cleaning up manifest...
Trimming unused files from manifest...
Creating PDF Output...
67% Running PDF Output plugin
The cover image has an id != "cover". Renaming to work around bug in Nook Color
68% Parsed all content for markup transformation
70% Completed markup transformation
WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed.
Traceback (most recent call last):
  File "/usr/bin/ebook-convert", line 20, in <module>
    sys.exit(main())
  File "/usr/lib/calibre/calibre/ebooks/conversion/cli.py", line 401, in main
    plumber.run()
  File "/usr/lib/calibre/calibre/ebooks/conversion/plumber.py", line 1275, in run
    self.opts, self.log)
  File "/usr/lib/calibre/calibre/ebooks/conversion/plugins/pdf_output.py", line 176, in convert
    self.convert_text(oeb_book)
  File "/usr/lib/calibre/calibre/ebooks/conversion/plugins/pdf_output.py", line 243, in convert_text
    log=self.log, cover_data=self.cover_data, report_progress=self.report_progress
  File "/usr/lib/calibre/calibre/ebooks/pdf/html_writer.py", line 1086, in convert
    manager = RenderManager(opts, log, container.root)
  File "/usr/lib/calibre/calibre/ebooks/pdf/html_writer.py", line 207, in __init__
    ans.setUrlRequestInterceptor(self.interceptor)
AttributeError: 'QWebEngineProfile' object has no attribute 'setUrlRequestInterceptor'

ebook-convert --version
ebook-convert (calibre 4.2.0)
Created by: Kovid Goyal <email address hidden>

Used on Debian testing: calibre 4.2.0+dfsg-2

Revision history for this message
Petr Vorel (petr-vorel) wrote :

Actually the error is AttributeError: 'QWebEngineProfile' object has no attribute 'setUrlRequestInterceptor'

Revision history for this message
Eli Schwartz (eschwartz) wrote : Re: [Bug 1850835] Re: WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed.

Calibre does not officially support Linux distribution packages. Try
uninstalling the Debian package and using the official binaries. If that
works, then you have a Linux distribution issue and must report a bug to
the Debian bugtracker. If it is still broken using the binary install, then
feel free to reopen this bug.

Note that the Debian package is rather bad quality either way.

 status invalid

Changed in calibre:
status: New → Invalid
Revision history for this message
Petr Vorel (petr-vorel) wrote :

OK, works with your tarball. I'll report it to Debian bug tracker. I wonder what package is missing.

Revision history for this message
Kovid Goyal (kovid) wrote : Re: calibre bug 1850835

That indicates the version of PyQt is too old.

Revision history for this message
Norbert Preining (preining) wrote :

Hi all,
yes indeed, Qt (not only PyQt) is at 5.12 in Debian, and setUrlRequestInterceptor was introduced in 5.13. The only place where this is used is in html_writer.py.

I see that the interceptor filters out/blocks all kind of non-local stuff (anything other than file://, and was introduced in e64b8b11fbe for 4.0.0.

Sad that for one single call 5.13 needs to be used.

@Eli Schwartz
> Note that the Debian package is rather bad quality either way.

I hear this from you at several places, without any particular explanation.
Is your aim simple bashing, or are you interested in a cooperation?
I can remove calibre from Debian, if this is your preference, it will hurt a lot of people.
Instead of permanently spreading FUD, please provide a list of things you consider bugs, and
I will look at them.

I am just sick of hearing the same old song from you over and over again.

Thanks

Revision history for this message
Kovid Goyal (kovid) wrote :

yes indeed, it is needed to ensure that converting arbitrary HTML/JS to PDF does not allow access to system files. Sadly this is pretty much a hard requirement, no way around it. I dont know if that is the only place in calibre that relies on Qt 5.13 though. You might want to stick with calibre 3.x until you are ready to use Qt 5.13+ in debian.

Revision history for this message
Eli Schwartz (eschwartz) wrote : Re: [Bug 1850835] Re: WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed.
Download full text (4.9 KiB)

> @Eli Schwartz
>> Note that the Debian package is rather bad quality either way.
>
> I hear this from you at several places, without any particular explanation.
> Is your aim simple bashing, or are you interested in a cooperation?

I mentioned a couple of points here, I think:
https://bugs.launchpad.net/calibre/+bug/1714107
At least in this bug report, there wasn't a context where it would be
useful to do a technical analysis of things I think could be improved --
a user wanted to successfully run calibre, and probably didn't care at
all about packaging.

Anyway: the build instructions for calibre are described at the bottom
of this page: https://calibre-ebook.com/download_linux

And it links to
https://github.com/kovidgoyal/calibre/blob/master/bypy/sources.json

Some of these are only needed for frozen builds which generate the fully
independent binaries, but for our purposes, let's consider the PyPI
items in this json file. This is, BTW, an important file to track -- if
a dependency is added here, it should most likely be added to downstream
distribution packages as well. Failure to do so results in calibre's
binary .so extensions compiling, and the setup.py install succeeding,
but calibre failing to run once installed due to missing module imports.

The Debian package for calibre has IIRC been rather plagued by missing
dependencies, e.g. html2text, html5lib, pyqtwebengine.

You still have some dreadfully ancient dependency on cherrypy. One of
the major features of calibre 3.0, which was a full major release cycle
ago, and 52 minor feature releases and counting, was the complete
removal of cherrypy due to the content server being reimplemented from
scratch.

You have habitually patched out calibre's vendored dependencies. This is
wrong. I have habitually submitted PRs to calibre to use the system
version of these dependencies -- this benefits all linux distributions
other than Debian. Some of these modules -- feedparser and markdown --
were public API for the recipe subsystem, so calibre includes an import
hook allowing 'import calibre.ebooks.markdown' or
'import calibre.web.feeds.feedparser' to still work (and use the system
version). But debian applies a tree-wide sed to replace the markdown
module, which no longer applies correctly since its targets no longer
exist. It does, however, rewrite the import hook -- now, it hooks into
any caller that does 'import markdown' and causes it to try to import
the '' (empty string) module. Please do not use sed in your build
recipes, patches are more reliable.

Note that while debian shipped python-markdown 3.x and it was not yet
devendored from calibre, this was broken in a different way -- calibre
was not source-compatible with markdown 3.x, my PR to devendor it
included updating calibre to work with 3.x

Debian has an ancient version of python-mechanize available, which
calibre does not work with (upstream development essentially died, then
Kovid received permission to take over development, and added numerous
improvements including python3 support, without which calibre could not
be ported to python3).

Debian patches calibre to use the system mathjax. I submitted a PR to
add a build option to...

Read more...

Revision history for this message
Petr Vorel (petr-vorel) wrote :

Hi all,

thank you for working to sort this error.

@Eli Schwartz Thank you for stating what is wrong in Debian, instead of just complaining about bad quality :).
I actually do care about being this fixed for Debian. It's nice you provide compiled packages, but still many people want to use software through distro packages.
I learnt from my role as developer for software, which is being used in some Linux distros and distro packager for other software both sides can gain a lot if they cooperate.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.