## Twisted web client and ssl (Since it took close to an hour to figure this out...) Written by Mike C. on Aug. 23, 2004 in Snaking.

The secret: twisted.web.client.getPage(url) handles SSL (https://) protocols automatically. Nothing I could find in the documentation mentions that. There are references to the ContextFactory, but nothing is mentioned about whether you need to pass one in or not (you don't). So, a simple script to download an SSL page with Twisted looks something like this:

from twisted.web import clientfrom twisted.internet import reactorif __name__ == "__main__":    def do( ):        df = client.getPage(            url = "https://www.vex.net/",            followRedirect = True,        )        def printOnError( error ):            print 'E', error        def printOnSuccess( page ):            print 'S', page        df.addErrback( printOnError )        df.addCallback( printOnSuccess )        return df    reactor.callWhenRunning( do )    reactor.run()

The thing that confused me was that the URLs I was testing with were all invalid, so when the client went to connect, it was receiving 501 errors, which I was assuming were due to a mis-configured SSL connection.

Anyway, think I'll head off to bed so I can get an early start and get in a nice long day of hacking before heading off to PyGTA.