Skip to content Skip to sidebar Skip to footer

Qwebengineview And Ignoring Cert Errors

I am trying to understand how this works and am struggling to figure out how to use it. The only examples I can find are not in Python and apparently I'm not that good at translati

Solution 1:

You have to override the certificateError() method of QWebEnginePage:

import sys


from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication


from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView


class WebEnginePage(QWebEnginePage):
    def certificateError(self, error):
        # If you want to ignore the certificates of certain pages
        # then do something like
        # if error.url() == QUrl("https://www.us.army.mil/"):
        #     error.ignoreCertificateError()
        #     return True
        # return super().certificateError(error)

        error.ignoreCertificateError()
        return True


def main(args):
    app = QApplication(args)
    webview = QWebEngineView()
    page = WebEnginePage()
    webview.setPage(page)
    webview.load(QUrl("https://www.us.army.mil/"))
    webview.show()
    sys.exit(app.exec_())


if __name__ == "__main__":
    main(sys.argv)
```

Post a Comment for "Qwebengineview And Ignoring Cert Errors"