[PyQt] QNetworkAccessManager.sslErrors in PyQt 5.2.1

Glenn Ramsey gr at componic.co.nz
Thu Jun 12 00:38:10 BST 2014


On 11/06/14 21:32, Glenn Ramsey wrote:
> On 11/06/14 20:43, Florian Bruhin wrote:
>> * Glenn Ramsey <gr at componic.co.nz> [2014-06-11 20:17:34 +1200]:
>>> I am trying to implement a fix for loading pages via https in QtWebKit as
>>> described in this thread:
>>>
>>> http://www.mail-archive.com/pyqt%40riverbankcomputing.com/msg21139.html
>>>
>>> It suggests to do this:
>>>
>>>          self.connect (self.browserWindow.page().networkAccessManager(),
>>> SIGNAL("sslErrors (QNetworkReply *, const QList<QSslError> &)"),
>>> self.sslErrorHandler)
>>>
>>>      def sslErrorHandler(self, reply, errorList):
>>>          reply.ignoreSslErrors()
>>>          print ("SSL error ignored")
>>>
>>>
>>> When I try it in PyQt5 (5.2.1)
>>>
>>> self._webView.page().networkAccessManager().sslErrors.connect(self.handleSslErrors)
>>>
>>>
>>> I get
>>>
>>> AttributeError: 'QNetworkAccessManager' object has no attribute 'sslErrors'
>>>
>>> Is this a bug, or am I doing it wrong?
>>
>> Works just fine here:
>>
>>      >>> from PyQt5.QtCore import QT_VERSION_STR
>>      >>> from PyQt5.QtWidgets import QApplication
>>      >>> from PyQt5.QtNetwork import QNetworkAccessManager
>>      >>> QT_VERSION_STR
>>      '5.2.0'
>>      >>> app = QApplication([])
>>      >>> nam = QNetworkAccessManager()
>>      >>> nam.sslErrors
>>      <bound signal sslErrors of QNetworkAccessManager object at
>> 0x00000000030A7828>
>>
>> Same in 5.3.0 as well.
>>
>> I wonder if you somehow got a Qt build without SSL support?
>>
>> The eric helpviewer by Detlev Offenbach (who is also on this ML, I
>> think) does in fact handle this explicitely, basically like this:
>>
>>      try:
>>          from PyQt4.QtNetwork import QSslSocket
>>          ...
>>          SSL_AVAILABLE = True
>>      except ImportError:
>>          SSL_AVAILABLE = False
>>
>>      ...
>>
>>      if SSL_AVAILABLE:
>>          ...
>>          self.sslErrors.connect(self.__sslErrorHandler.sslErrorsReplySlot)
>>
>>
>> Florian
>
> Thanks Florian, that was the problem. My Qt was built without SSL support.
>

Just some notes for the next person that has this issue, because it wasn't 
immediately obvious what to do...

The above issue was on Windows. When building Qt on OSX, QtWebkit gets built 
with OpenSSL support by default, at least that's what happened when I built it, 
which is why I was confused about it not being available on Windows.

To get WebKit built on Windows you need to install and build icu 
(http://site.icu-project.org/), add -icu to the configure command and set the 
INCLUDE and LIB env vars, and install the extra tools as described here:
http://doc.qt.digia.com/qt-5.2/windows-requirements.html
Also the icu bin dir has to be on your path.

That should get QtWebKit built, but it won't have SSL support. For that you need 
to build OpenSSL from openssl.org, add it to the INCLUDE and LIB env vars and 
add -openssl to the configure line.



More information about the PyQt mailing list