QNetworkAccessManager https UnknownNetworkError when using pyside2
-
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
-
Hi and welcome to devnet,
Do you also have OpenSSL available on your machine ?
-
Yes, and when I tried to run using the command line, these errors popup.
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 -
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.
-
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 ?!!
-
The Qt Online Installer has an option to download a suitable version of OpenSSL.
How are you installing PySide2 ?
-
I installed it using pip
pip install pyside2I'm on windows using python 3.7