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
and error string: 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:
- pyside2 on windows: fails
- pyside2 on mac: works fine
- on windows: works fine
- pyqt5 on mac: works fine
and I’m stuck with it for a while and can’t seem to find the problem.
I’m using python 3.7 and pyside2 5.15. also, I tested with pyside2 5.12.6 and the same error occurs.
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()