[PyQt] Transferring security context to newly created QWebView windows

alan moore me at alandmoore.com
Sun Jun 17 04:50:17 BST 2012


Realized I forgot to mention what this code does.

It opens a password-protected page which contains a link to another page 
in the same password-protected folder and opens up in a new window.

The expected behavior is that the second page will open fine, since 
we're already authenticated to the security context.  The actual 
behavior is that you get a 403 error.

Please, I've been trying to figure this out for a long time, if anyone 
can point me in the right direction I'd appreciate it.

On 06/13/2012 02:14 PM, me at alandmoore.com wrote:
> Below is some code that illustrates a problem I've been having for several
> months now.  I've got a widget based on the QWebView that needs to be able
> to open pop-up windows (e.g., links with target="_blank" or javascript
> window.open() calls) in a password-protected context.
>
> I can get the windows created just fine by overriding createWindow, but
> the security credentials are not transferred over.  In "real" web browsers
> (firefox/chrome/opera/rekonq/etc), once authenticated any subsequent
> windows in the security context work fine.  How do I recreate this behavior
> in a QWebView?
>
> See example code:
>
> ######################
> # Begin Code Example #
> ######################
>
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> from PyQt4.QtWebKit import *
> import sys
>
> class mybrowser(QWebView):
>
>      def __init__(self, parent=None):
>          super(mybrowser, self).__init__(parent)
>          url = QUrl ("http://www.alandmoore.com/wwwtest")
>          url.setUserName("test")
>          url.setPassword("test123")
>          self.load(url)
>
>      def createWindow(self, type):
>          self.w = mybrowser()
>          self.w.show()
>          return self.w
>
> if __name__ == '__main__':
>      app = QApplication(sys.argv)
>      w = mybrowser()
>      w.show()
>      app.exec_()
>
> ####################
> # End Code Example #
> ####################
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



More information about the PyQt mailing list