[PyQt] Cancelling QtWebEngine authentication with PyQt
Phil Thompson
phil at riverbankcomputing.com
Wed Dec 14 15:22:06 GMT 2016
On 14 Dec 2016, at 11:38 am, Florian Bruhin <me at the-compiler.org> wrote:
>
> * 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())
I've called it assign() as it invokes the assignment operator.
The following code works...
import sip
from PyQt5.QtNetwork import QAuthenticator
a = QAuthenticator()
assert a.isNull()
a.setUser("foo")
assert not a.isNull()
sip.assign(a, QAuthenticator())
assert a.isNull()
It is in current hg and tonight's snapshot.
Phil
More information about the PyQt
mailing list