PyQt加载页面 - 检查错误ErrorPageExtension

时间:2017-03-13 10:41:10

标签: python-3.x pyqt pyqt5 qtwebkit qtwebview

我正在尝试加载一个静态html页面但是我将加载页面视为false。 (这在本地工作但不在docker容器内。)

文件loadProgress是100%,但我得到的信号为false,表示加载页面时出错。 我正在尝试使用ErrorPageExtension(从在线找到)来确定详细的错误消息是什么。 有人可以在加载页面时如何在出现错误时调用扩展名吗?我错过了什么吗?

  def setupWebView(self):
    # setting up web view objects
    #bla bla
    self._extension_handlers = {
      QWebPage.ErrorPageExtension: self._handle_errorpage,
    }

  def loadSetPage(self):
    print(":: OS Path is:"+os.getcwd())
    self.url2 = QUrl("file://"+os.getcwd()+"/dist/index.html")
    self.web2.load(self.url2)
    print("Checking if Load Page was successful")
    self.web2.loadFinished.connect(self.testIfPageLoaded)


  def testIfPageLoaded(self, ok):
    print(":: Loading of page finished successfully")
    testhtml = self.web2.page().currentFrame().toHtml()
    print(ok)  ##

 def _handle_errorpage(self, info, errorPage):
    # catch the error, populate self.errorInfo and return an error page
    info = sip.cast(info, QWebPage.ErrorPageExtensionOption)
    print("The error loading page is : "+info.errorString)
    return True

  def supportsExtension(self, ext):
    return ext in self._extension_handlers

  def extension(self, ext, opt, out):
    try:
      handler = self._extension_handlers[ext]
    except KeyError:
      print("Extension {} not supported!".format(ext))
      return super().extension(ext, opt, out)
    return handler(opt, out)

0 个答案:

没有答案