[Twisted-Python] 'module' object has no attribute 'optionsForClientTLS'

Orbitus orbitus at orbitusrobotics.com
Thu Oct 2 20:55:24 MDT 2014


I am trying to execute the check_server_certificate.py and I am getting this error… can you guys help me figure out whats going on? its the exact sample code on the website running on Ubuntu 14.04.


Here is the error output:

Traceback (most recent call last):
  File "check_server_certificate.py", line 28, in <module>
    task.react(main, sys.argv[1:])
  File "/usr/lib/python2.7/dist-packages/twisted/internet/task.py", line 867, in react
    finished = main(_reactor, *argv)
  File "check_server_certificate.py", line 6, in main
    options = ssl.optionsForClientTLS(hostname=host.decode('utf-8'))
AttributeError: 'module' object has no attribute 'optionsForClientTLS'


Here is the code (check_server_certificate.py):


from __future__ import print_function
import sys
from twisted.internet import defer, endpoints, protocol, ssl, task, error

def main(reactor, host, port=443):
    options = ssl.optionsForClientTLS(hostname=host.decode('utf-8'))
    port = int(port)

    class ShowCertificate(protocol.Protocol):
        def connectionMade(self):
            self.transport.write(b"GET / HTTP/1.0\r\n\r\n")
            self.done = defer.Deferred()
        def dataReceived(self, data):
            certificate = ssl.Certificate(self.transport.getPeerCertificate())
            print("OK:", certificate)
            self.transport.abortConnection()
        def connectionLost(self, reason):
            print("Lost.")
            if not reason.check(error.ConnectionClosed):
                print("BAD:", reason.value)
            self.done.callback(None)

    return endpoints.connectProtocol(
        endpoints.SSL4ClientEndpoint(reactor, host, port, options),
        ShowCertificate()
    ).addCallback(lambda protocol: protocol.done)

task.react(main, sys.argv[1:])



Rudy Aramayo | Developer | OrbitusRobotics LLC
Direct: 626.386.8329 | Email: orbitus at orbitusrobotics.com | Web: www.orbitusrobotics.com

           

"This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify me (orbitus at orbitusrobotics.com). If you are not the named addressee you should not disseminate, distribute or copy this e-mail and should delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.”




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20141002/1864a75c/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OrbitusRobotics_white-logo.png
Type: image/png
Size: 16993 bytes
Desc: not available
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20141002/1864a75c/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.jpg
Type: image/jpeg
Size: 2323 bytes
Desc: not available
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20141002/1864a75c/attachment-0004.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.jpg
Type: image/jpeg
Size: 2617 bytes
Desc: not available
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20141002/1864a75c/attachment-0005.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.jpg
Type: image/jpeg
Size: 2536 bytes
Desc: not available
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20141002/1864a75c/attachment-0006.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.jpg
Type: image/jpeg
Size: 1917 bytes
Desc: not available
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20141002/1864a75c/attachment-0007.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20141002/1864a75c/attachment-0001.pgp>


More information about the Twisted-Python mailing list