QNetworkAccessManager https UnknownNetworkError when using pyside2

Heads up! You've already completed this tutorial.

ma432225568 | 2020-07-23 17:22:04 UTC | #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:

python
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

Create GUI Applications with Python & Qt6 by Martin Fitzpatrick — (PyQt6 Edition) The hands-on guide to making apps with Python — Over 10,000 copies sold!

More info Get the book


Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak
Martin Fitzpatrick

QNetworkAccessManager https UnknownNetworkError when using pyside2 was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt. Martin founded PythonGUIs to provide easy to follow GUI programming tutorials to the Python community. He has written a number of popular https://www.martinfitzpatrick.com/browse/books/ on the subject.