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

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Wed Jul 4 07:09:45 EDT 2012


On 3 Jul, 09:54 pm, mobilebackup77 at gmail.com wrote:
>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.

nose used to support Twisted with some gross, arguably incorrect code. 
I don't know if this is still the case, but it's perhaps something to 
investigate.

Apart from that, getPage uses Twisted's regular ("standard"?  "only"?) 
SSL support to do HTTPS.  There *shouldn't* be anything particular to 
getPage that would cause the handshake to fail, so either Twisted's SSL 
support is broken in general in whatever configuration you're using, or 
the problem isn't in Twisted.

Jean-Paul



More information about the Twisted-Python mailing list