[Twisted-Python] bug or my code? (getPage + Twisted Webserver = Exception)

Me Myself mobilebackup77 at gmail.com
Tue Jul 3 15:54:18 MDT 2012


Hi All,

I have a flask application that I am running on a https twisted
webserver and forwarding the port to a url. Everything works well. I
can goto the url using firefox, accept the certificate and get in.

I have a small nose test to test if the url is up. Here is the test:

    @deferred(timeout = 31)
    @defer.inlineCallbacks
    def test_if_forwarding_url_is_ready(self):
        """
            furl: Check if url is accessible
        """
        # First wait for 10 seconds
        yield task.deferLater(reactor, 10, lambda:None)
        delay = 2
        secureurl = Config.General.url
        # Every two seconds do a query and find out if you can get
        # data from the mapped url. If you can, then exit
        for i in range(15):
            got_data = False
            print "Trial :", i
            try:
                output = yield getPage(secureurl)
                got_data = True
            except Exception as E:
                print "Exception occurred:", E
                got_data = False
            if got_data == True:
                assert "secure magic" in output
                return
            yield task.deferLater(reactor, delay, lambda:None)
        # All 15 trials to get data from the url failed
        assert False

When the test is run, it fails "most of the time" and outputs:

Exception occurred: [('SSL routines', 'SSL23_READ', 'ssl handshake failure')]

But if I run the test and right away goto the secureurl manually using
firefox or chrome, as soon as I am on the webpage, the test passes!
Sometimes I've seen the test will pass after 8 trials, if that is when
I can type the url in firefox and press enter!

Any ideas what is causing this and how to fix it? Maybe I am doing
something stupid and perhaps someone can help me rewrite this code.

Thanks,
--Ram




More information about the Twisted-Python mailing list