[Twisted-web] HTTPClientFactory questions

snacktime snacktime at gmail.com
Tue Feb 8 23:25:20 MST 2005

I'm trying to figure out the best way to catch all the different
possible errors when using HTTPClientFactory and am kind of stuck.

First, what is the best way to catch errors before or during the
connection, such as connection time outs or dns lookup errors? If a
response isn't sent to the client, status,version, and message will
never get set.  I need the status code for all responses, but I need a
way to catch all errors that don't set the status so I know if status
is available or not.

I tried inheriting HTTPClientFactory and providing my own
clientConnectionFailed() method, and that's when I ran into another
issue.  I happened to try connecting to a host that gave me an ssl
handshake failure, and an exception was caught in twisted.internet.tcp
and printed.  However it didn't register an errback but went ahead
with the callback (complete code is below).

from twisted.internet import reactor,ssl
from twisted.web.client import HTTPClientFactory
import sys

class Test:

  def Start(self):
      self.factory = HTTPClientFactory('https://www.he.net',method='GET')
      contextFactory = ssl.ClientContextFactory()
      reactor.connectSSL('www.he.net', 443, self.factory, contextFactory)

  def Success(self,data):
    print "Success: %s " % data

  def Error(self,data):
     print "Error: %s " % data

c = Test()

More information about the Twisted-web mailing list