Anwar Mohamed
Anwar Mohamed

Reputation: 653

AttributeError: 'NoneType' object has no attribute 'connectSSL'

I am programming a ssl client to my server where it uses python twisted with pyqt4, I used QTReactor for twisted in PYQT but when I run the code there is an error

AttributeError: 'NoneType' object has no attribute 'connectSSL'

my initial code it like this

from OpenSSL import SSL
import sys
from twisted.internet.protocol import ClientFactory
from twisted.protocols.basic import LineReceiver
from twisted.internet import ssl
import qt4reactor

app = QtGui.QApplication(sys.argv)
reactor=qt4reactor.install()
main()
myapp = MainForm()
myapp.show()
reactor.runReturn()
sys.exit(app.exec_())

def main():
    factory = ClientFactory()
    reactor.connectSSL('localhost', 8080, factory, ssl.ClientContextFactory())
    try:
        reactor.run()
    except KeyboardInterrupt:
        reactor.stop()

the error when i run it:

Traceback (most recent call last):
  File "client.py", line 51, in <module>
    main()
  File "client.py", line 40, in main
    reactor.connectSSL('localhost', 8080, factory, ssl.ClientContextFactory())
AttributeError: 'NoneType' object has no attribute 'connectSSL'

Upvotes: 1

Views: 2471

Answers (2)

David Heffernan
David Heffernan

Reputation: 613332

AttributeError: 'NoneType' object has no attribute 'connectSSL'

is the error message that you get when you try to invoke a method on None.

This line of code

reactor=qt4reactor.install()

is the only place where reactor is assigned. The error message makes it clear that reactor is being assigned the value None.

All the web search hits that I can find on the topic follow this pattern:

qt4reactor.install(app)
from twisted.internet import reactor

and so I guess that's how you are meant to do it. But I do confess to knowing precisely nothing about these frameworks.

Upvotes: 6

Wladimir Palant
Wladimir Palant

Reputation: 57681

qt4reactor.install() doesn't return a value so that reactor ends up being None. So when you attempt to call a method of reactor you get this error (obviously, None doesn't have any methods). If I see it correctly, the proper way of getting the reactor variable is this:

qt4reactor.install(app)
from twisted.internet import reactor

Upvotes: 2

Related Questions