Qt HTTP Authentication Using QNetworkAccessManager

I am working with a web service that requires a valid username / password. From PyQt, I access the web service using the QNetworkAccessManager, which emits

authenticationRequired (QNetworkReply*, QAuthenticator*)

when (obviously) authentication is required. When I populate the user and psswd for QAuthenticator, everything works fine. However, I do not see how to break the loop when the user is invalid.

In the docs for authenticationRequired:

"If he rejects the credentials, that signal will be deleted again."

For invalid credentials, this signal is emitted again and again, and again ... Looking at the error code in the response showed 0. How should this cycle be broken or processed so that it ends with an error?

+3
source share
4 answers

Yes, this is strange. What I did earlier is checking if I have already authenticated with this data and if I have a callQNetworkReply.abort()

+2
source

How about trying:

QNetworkReply::abort()

or

QNetworkReply::close()

?

+1
source

QNetworkReply::abort() "Operation Aborted" 401. , , , , QAuthenticator::setUser() QAuthenticator::setPassword() authenticationRequired(). QAuthenticatorPrivate::phase Done, , .

Qt .

Qt 4.7 - Qt 4.8.

0

, & QNetworkAccessManager:: proxyAuthenticationRequired - QAuthenticator, HTTP- (, 401 407).

, QAuthenticator:: setUser setPassword, , Cancel. : -)

, & QNetworkAccessManager:: authenticationRequired ( QNetworkReply:: abort(), QAuthenticator, HTTP, abort() ).

0

Source: https://habr.com/ru/post/1714519/


All Articles