title: How to catch exception for which the name is not defined in context?
body: <p>I am seeing the <a href="http://www.python-requests.org/" rel="nofollow">python-requests library</a> crash with the following traceback:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/usr/lib/python3.2/http/client.py", line 529, in _read_chunked
      chunk_left = int(line, 16)
  ValueError: invalid literal for int() with base 16: b''
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "./app.py", line 507, in getUrlContents
      response = requests.get(url, headers=headers, auth=authCredentials, timeout=http_timeout_seconds)
    File "/home/dotancohen/code/lib/requests/api.py", line 55, in get
      return request('get', url, **kwargs)
    File "/home/dotancohen/code/lib/requests/api.py", line 44, in request
      return session.request(method=method, url=url, **kwargs)
    File "/home/dotancohen/code/lib/requests/sessions.py", line 338, in request
      resp = self.send(prep, **send_kwargs)
    File "/home/dotancohen/code/lib/requests/sessions.py", line 441, in send
      r = adapter.send(request, **kwargs)
    File "/home/dotancohen/code/lib/requests/adapters.py", line 340, in send
      r.content
    File "/home/dotancohen/code/lib/requests/models.py", line 601, in content
      self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
    File "/home/dotancohen/code/lib/requests/models.py", line 542, in generate
      for chunk in self.raw.stream(chunk_size, decode_content=True):
    File "/home/dotancohen/code/lib/requests/packages/urllib3/response.py", line 222, in stream
      data = self.read(amt=amt, decode_content=decode_content)
    File "/home/dotancohen/code/lib/requests/packages/urllib3/response.py", line 173, in read
      data = self._fp.read(amt)
    File "/usr/lib/python3.2/http/client.py", line 489, in read
      return self._read_chunked(amt)
    File "/usr/lib/python3.2/http/client.py", line 534, in _read_chunked
      raise IncompleteRead(b''.join(value))
  http.client.IncompleteRead: IncompleteRead(0 bytes read)
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
      self.run()
    File "./app.py", line 298, in run
      self.target(*self.args)
    File "./app.py", line 400, in provider_query
      url_contents = getUrlContents(str(providerUrl), '', authCredentials)
    File "./app.py", line 523, in getUrlContents
      except http.client.IncompleteRead as error:
  NameError: global name 'http' is not defined
  </code></pre>
  
  <p>As can be seen, I've tried to catch the <code>http.client.IncompleteRead: IncompleteRead(0 bytes read)</code> error that <code>requests</code> is throwing with the line <code>except http.client.IncompleteRead as error:</code>. However, that is throwing a <code>NameError</code> due to <code>http</code> not being defined. <strong>So how can I catch that exception?</strong></p>
  
  <p>This is the code throwing the exception:</p>
  
  <pre><code>import requests
  from requests_oauthlib import OAuth1
  
  authCredentials = OAuth1('x', 'x', 'x', 'x')
  response = requests.get(url, auth=authCredentials, timeout=20)
  </code></pre>
  
  <p>Note that I am not including the <code>http</code> library, though <code>requests</code> is including it. The error is very intermittent (happens perhaps once every few hours, even if I run the <code>requests.get()</code> command every ten seconds) so I'm not sure if added the <code>http</code> library to the imports has helped or not.</p>
  
  <p>In any case, in the general sense, <strong>if included library A in turn includes library B, is it impossible to catch exceptions from B without including B myself?</strong></p>