Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Question related to HTTP requests and HTTP-Digest
Forum Updated to NodeBB v4.3 + New Features

Question related to HTTP requests and HTTP-Digest

Scheduled Pinned Locked Moved Unsolved Qt for Python
1 Posts 1 Posters 150 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LS-KS
    wrote on last edited by
    #1

    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?
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved