Question related to HTTP requests and HTTP-Digest
-
I have a Qt-Application written in Pyside6 that needs to communicate to an ABB IRC5 controller via http API.
I have a manual that delivers an example script that uses the requests module to establish a connection using
requests.session and HttpDigestAuth to login and then uses a websocket for subscriptions.I would like to do similar but with Qt classes.
Unfortunately I wasn't able to get all information I need when reading this page link.
From my understanding I need to instantiate QNetworkAccessManager that handles my request and cookies.
To use the Digest-MD5 method I instantiate QAuthenticator. But here comes the first problem:How to use the setOption() method correctly? What should be the second argument? It's clear for the C++ class, but not for the PySide6 class.
How to tell QNetWorkAccessManager instance to use QAutenticator instance to perform a post-request?
I made a minimal working example with two QWebsocket at localhost and played around with QNetworkRequests which worked fine. But using the actual URL of the controller i don't get any response. If I use cURL with the same username and password together with the -digest flag it works as expected.
Hope someone sees my error and has some good hints :-)
def try_abb_connect(self): self.authenticate("Default User", "robotics") payload = b"lvalue=1" url = QUrl("http://168.168.64.61/rw/iosystem/signals/Virtual1/Board1/di1?action = set") request = QNetworkRequest(url) request.setHeader(QNetworkRequest.KnownHeaders.ContentTypeHeader, "application/x-www-form-urlencoded") resp = self.manager.post(request, payload) print("ABB: " + str(resp.error()) + resp.errorString()) #below is the line from an example using requests module: #resp = requests.post("http://localhost/rw/iosystem/signals/Virtual1/Board1 / di1?action = set", auth = HTTPDigestAuth("Default User", "robotics"), data = payload) def authenticate(self, username: str, password: str): self.authenticator: QAuthenticator = QAuthenticator() self.authenticator.setOption("Digest", self.authenticator) self.authenticator.setUser(username) self.authenticator.setPassword(password) # here: how to connect authenticator to network manager?