title: Handling Failure in Twisted
body: <p>This is my simple HTTP client for some api:</p>
  
  <blockquote>
  <pre><code># -*- coding: utf-8 -*-
  import settings
  from twisted.internet import reactor
  from twisted.web.client import Agent
  from twisted.web.http_headers import Headers
  
  params = {
      'url': 'http://api.vk.com/api.php',
      'id':260,
      }
  
  
  def params_for_get():
      return '&amp;'.join(["%s=%s" % (key,val) for key, val in params.items()])
  
  
  agent = Agent(reactor)
  d = agent.request(
      'GET',
      "%s?%s" % (settings.APPLICATION_URL, params_for_get()),
      Headers({'User-Agent': ['Twisted Web Client Example'],
               'Content-Type': ['text/x-greeting']}),
      '')
  
  def cbResponse(*args, **kwargs):
      print args, kwargs
      print 'Response received'
  
  
  def cbShutdown(ignored):
      reactor.stop()
  
  def cbError(failure):
      print type(failure.value), failure # catch error here
  
  
  d.addCallbacks(cbResponse, cbError)
  d.addBoth(cbShutdown)
  
  
  reactor.run()
  </code></pre>
  </blockquote>
  
  <p>When I start program, I catch error:</p>
  
  <pre><code>&lt;class 'twisted.web._newclient.RequestGenerationFailed'&gt; [Failure instance: Traceback (failure with no frames): &lt;class 'twisted.web._newclient.RequestGenerationFailed'&gt;: [&lt;twisted.python.failure.Failure &lt;type 'exceptions.AttributeError'&gt;&gt;]
  ]
  </code></pre>
  
  <p>But I don't know, where this error happened.
  How I can know it?
  I tried to display traceback for </p>
  
  <pre><code>&lt;twisted.python.failure.Failure &lt;type 'exceptions.AttributeError'&gt;&gt;
  </code></pre>
  
  <p>but I could not get.</p>