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. QNetworkAccessManager https UnknownNetworkError when using pyside2
Forum Updated to NodeBB v4.3 + New Features

QNetworkAccessManager https UnknownNetworkError when using pyside2

Scheduled Pinned Locked Moved Unsolved Qt for Python
pyside2qt for pythonpython
7 Posts 2 Posters 1.4k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    belalshehab
    wrote on last edited by
    #1

    Hello, I’m using the QNetworkAccessManager module and it works fine with HTTP requests, but when I try to do https requests it fails and returns “PySide2.QtNetwork.QNetworkReply.NetworkError.UnknownNetworkError: TLS initialization failed”
    this problem only happens with pyside2 on windows.
    but it works fine on Mac os.
    when I used the same piece of code with pyqt5 it worked just fine on both Windows and Mac os.
    https requests:
    1.pyside2 on windows: fails
    2.pyside2 on mac: works fine
    3. pyqt5 on windows: works fine
    4. pyqt5 on mac: works fine
    and I’m stuck with it for a while and can’t seem to find the problem.

    from PySide2 import QtNetwork
    from PySide2 import QtCore
    import sys, json
    
    class Example:
    
    def __init__(self):
        self.nam = QtNetwork.QNetworkAccessManager()
        self.nam.finished.connect(self.handle_response)
    
    def do_request(self):
        url = 'https://httpbin.org/get'
        req = QtNetwork.QNetworkRequest(QtCore.QUrl(url))
        self.nam.get(req)
    
    def handle_response(self, reply):
        er = reply.error()
        if er == QtNetwork.QNetworkReply.NoError:
            bytes_string = reply.readAll()
            print(str(bytes_string, 'utf-8'))
        else:
            print(f'Error occurred: {er}: {reply.errorString()}')
        QtCore.QCoreApplication.quit()
    def main():
    app = QtCore.QCoreApplication([])
    ex = Example()
    ex.do_request()
    sys.exit(app.exec_())
    
    if name == ‘main’:
    main()
    

    I’m using python 3.7 and pyside2 5.15

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Do you also have OpenSSL available on your machine ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        belalshehab
        wrote on last edited by belalshehab
        #3

        Yes, and when I tried to run using the command line, these errors popup.
        0b66cde7-49e2-4c38-8e67-38e9248e35fa-image.png
        0dd2c7b5-fdee-41fa-8cb9-9b632492a840-image.png
        17efd56f-0ab1-4aa6-8b80-f4df9155c5b0-image.png

        and I configured the environment variable to point to
        located on C:\Program Files\OpenSSL-Win64\bin
        and I'm not sure why It is searching the C:\WINDOWS path

        32f4dbbc-fff8-4cdb-826d-055b94421421-image.png

        a3a95442-3d9d-48a3-8d95-c3c99b71fb06-image.png

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Because it's higher in the list.

          But in any case, having OpenSSL in the Windows folder is usually a bad sign. That's typically a library that shall be provided along an application and not forced there.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • B Offline
            B Offline
            belalshehab
            wrote on last edited by belalshehab
            #5

            I looked into the pyside2 package installed on my machine and it seems that it doesn't come with its own libssl-1_1-x64.dll unlike pyqt5 package which comes with its own version.

            I don't know what version that pyside2 requires, and how to fix this ?!!

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              The Qt Online Installer has an option to download a suitable version of OpenSSL.

              How are you installing PySide2 ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • B Offline
                B Offline
                belalshehab
                wrote on last edited by
                #7

                I installed it using pip
                pip install pyside2

                I'm on windows using python 3.7

                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