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

Me Myself mobilebackup77 at gmail.com
Wed Jul 4 16:19:06 EDT 2012

Thanks for the quick reply Jean-Paul. I just removed nose from the
equation. And now, only firefox or chrome can actually get to the
webpages/Twisted webserver, but getPage keeps printing that exception.
It seems I've reduced the problem to getPage. I ran a separate thread
and used urlopen, and even that can actually get the https webpage
hosted on the twisted server. It seems getPage's https support/tests
need to be extended perhaps? (I wish I could help find the bug). I
know I need to isolate the bug from my project into a simple example
that can illustrate the bug. Unfortunately, I'm not sure I've the time
to do that right now.

On Wed, Jul 4, 2012 at 7:09 AM,  <exarkun at twistedmatrix.com> wrote:
> 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
>>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
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

More information about the Twisted-Python mailing list