title: Why am I getting an AttributeError when trying to print out
body: <p>I am learning about urllib2 by following this tutorial <a href="http://docs.python.org/howto/urllib2.html#urlerror">http://docs.python.org/howto/urllib2.html#urlerror</a> Running the code below yields a different outcome from the tutorial</p>
  
  <pre><code>import urllib2
  
  req = urllib2.Request('http://www.pretend-o-server.org')
  try:
      urllib2.urlopen(req)
  except urllib2.URLError, e:
      print e.reason
  </code></pre>
  
  <p>Python interpreter spits this back</p>
  
  <pre><code>Traceback (most recent call last):
    File "urlerror.py", line 8, in &lt;module&gt;
      print e.reason
  AttributeError: 'HTTPError' object has no attribute 'reason'
  </code></pre>
  
  <p><strong>How come this is happening?</strong> </p>
  
  <h2>UPDATE</h2>
  
  <p>When I try to print out the code attribute it works fine </p>
  
  <pre><code>import urllib2
  
  req = urllib2.Request('http://www.pretend-o-server.org')
  try:
      urllib2.urlopen(req)
  except urllib2.URLError, e:
      print e.code
  </code></pre>