[PyQt] Cancelling QtWebEngine authentication with PyQt

Florian Bruhin me at the-compiler.org
Wed Dec 14 11:38:53 GMT 2016


* Phil Thompson <phil at riverbankcomputing.com> [2016-12-14 11:08:15 +0000]:
> On 6 Dec 2016, at 6:06 am, Florian Bruhin <me at the-compiler.org> wrote:
> > 
> > Hi,
> > 
> > QtWebEngine requires setting the passed QAuthentication pointer to an
> > empty QAuthenticator to cancel authentication
> > ("*authenticator = QAuthenticator();" in authenticationRequired), see
> > the note here:
> > 
> > http://doc-snapshots.qt.io/qt5-5.7/qtwebenginewidgets-qtwebkitportingguide.html#qt-webengine-does-not-interact-with-qnetworkaccessmanager
> > 
> > Unfortunately I can't see a way to do this from PyQt, apart from
> > using setHtml to display some error (which seems a bit hacky to me):
> > 
> > https://github.com/kovidgoyal/vise/commit/749a9c693e4107c073a90042b079dc658ad73564
> > 
> > Not sure what the best way to solve this would be though...
> 
> Sorry, I'm not understanding. What is it you want to do in Python that you can't?

QtWebEngine calls authenticationRequired with a pointer to a non-null
QAuthenticator.

To cancel the authentication, the passed pointer needs to be set to a
new null QAuthenticator:

    // slot connected to QWebEnginePage::authenticationRequired
    void Foo::handleAuthenticationRequired(const QUrl &url, QAuthenticator *authenticator)
    {
        *authenticator = QAuthenticator();
    }

Since PyQt's signature is also "QUrl, QAuthenticator" (i.e. my code
gets a QAuthenticator as argument, it doesn't return any) there's no
way for it to return None or a new null QAuthenticator.

Solutions I can think of (unless I'm missing something):

- Having something like:
  sip.writepointer(authenticator, QAuthenticator())

- Marking the authenticator as /Out/, but changing the signature at
  that point might be troublesome?

- The same with backwards-compatibility: Passing the QAuthenticator
  like Qt does, but taking the returned QAuthenticator if one was
  returned from Python.

- Having something like QAuthenticator::clear() added in PyQt (which
  doesn't exist in Qt, because it's not needed there)

Does that makes sense?

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161214/f62574d6/attachment.sig>


More information about the PyQt mailing list