Results 1 to 3 of 3

Thread: Transferring session & auth data when QWebView calls createWindow()

  1. #1
    Join Date
    Jul 2012
    Location
    Southern USA
    Posts
    2
    Qt products
    Platforms
    Unix/X11

    Default Transferring session & auth data when QWebView calls createWindow()

    Hello, I'm new to these forums. I have posted this question to the PyQT mailing list several weeks ago, but got no response whatsoever, so I thought I'd try here.

    I have a web browser application written in PyQt4 which uses a subclassed QWebView. If I load a URL that is password protected, or uses a web session (such as php session) for security, and then subsequently click a link that opens a new window (e.g. target="_blank" or javascript window.open()), the new window opens without authentication or session data and a 403 error results.

    The following code illustrates this problem by opening a password-protected page on my website where you can click a link with "target=_blank" set.

    Qt Code:
    1. from PyQt4.QtCore import *
    2. from PyQt4.QtGui import *
    3. from PyQt4.QtWebKit import *
    4. import sys
    5.  
    6. class mybrowser(QWebView):
    7.  
    8. def __init__(self, parent=None):
    9. super(mybrowser, self).__init__(parent)
    10. url = QUrl ("http://www.alandmoore.com/wwwtest")
    11. url.setUserName("test")
    12. url.setPassword("test123")
    13. self.load(url)
    14.  
    15. def createWindow(self, type):
    16. self.w = mybrowser()
    17. self.w.show()
    18. return self.w
    19.  
    20. if __name__ == '__main__':
    21. app = QApplication(sys.argv)
    22. w = mybrowser()
    23. w.show()
    24. app.exec_()
    To copy to clipboard, switch view to plain text mode 

    How can I get new windows to retain the security credentials of the parent window?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Transferring session & auth data when QWebView calls createWindow()

    The easiest way would probably be to share the network access manager instance between the two windows.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2012
    Location
    Southern USA
    Posts
    2
    Qt products
    Platforms
    Unix/X11

    Default Re: Transferring session & auth data when QWebView calls createWindow()

    Thanks for your help. I tried changing the createWindow method to:
    Qt Code:
    1. def createWindow(self, type):
    2. self.w = mybrowser()
    3. self.w.page().setNetworkAccessManager(self.page().networkAccessManager())
    4. self.w.show()
    5. return self.w
    To copy to clipboard, switch view to plain text mode 

    But that causes a segfault. What's the basic MO for sharing a networkAccessManager?


    Added after 1 1:


    Ok, I think I got it figured out; this seems to work:

    Qt Code:
    1. from PyQt4.QtCore import *
    2. from PyQt4.QtGui import *
    3. from PyQt4.QtWebKit import *
    4. from PyQt4.QtNetwork import *
    5. import sys
    6.  
    7. class mybrowser(QWebView):
    8.  
    9. def __init__(self, parent=None, nam=None):
    10. super(mybrowser, self).__init__(parent)
    11. self.nam = nam or QNetworkAccessManager()
    12. self.page().setNetworkAccessManager(self.nam)
    13. url = QUrl ("http://www.alandmoore.com/wwwtest")
    14. url.setUserName("test")
    15. url.setPassword("test123")
    16. self.load(url)
    17.  
    18. def createWindow(self, type):
    19. self.w = mybrowser(None, self.nam)
    20. self.w.show()
    21. return self.w
    22.  
    23. if __name__ == '__main__':
    24. app = QApplication(sys.argv)
    25. w = mybrowser()
    26. w.show()
    27. app.exec_()
    To copy to clipboard, switch view to plain text mode 

    Thanks for pointing me in the right direction!!
    Last edited by admoore; 14th July 2012 at 04:54.

Similar Threads

  1. webview createWindow for javascrip applet
    By wambagilles in forum Qt Programming
    Replies: 2
    Last Post: 22nd March 2011, 23:00
  2. Replies: 1
    Last Post: 3rd March 2010, 08:04
  3. Posting data to QWebView
    By chrisb123 in forum Newbie
    Replies: 5
    Last Post: 29th October 2009, 06:58
  4. Replies: 1
    Last Post: 2nd July 2007, 12:04
  5. Transferring data input from a Widget to a cpp file
    By Ahmad in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2007, 09:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.