title: Fetch a file from a local url with Python requests?
body: <p>I am using Python's <a href="http://docs.python-requests.org/en/latest/index.html" rel="noreferrer">requests</a> library in one method of my application. The body of the method looks like this:</p>
  
  <pre><code>def handle_remote_file(url, **kwargs):
      response = requests.get(url, ...)
      buff = StringIO.StringIO()
      buff.write(response.content)
      ...
      return True
  </code></pre>
  
  <p>I'd like to write some unit tests for that method, however, what I want to do is to pass a fake local url such as:</p>
  
  <pre><code>class RemoteTest(TestCase):
      def setUp(self):
          self.url = 'file:///tmp/dummy.txt'
  
      def test_handle_remote_file(self):
          self.assertTrue(handle_remote_file(self.url))
  </code></pre>
  
  <p>When I call <strong>requests.get</strong> with a local url, I got the <strong>KeyError</strong> exception below:</p>
  
  <pre><code>requests.get('file:///tmp/dummy.txt')
  
  /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/requests/packages/urllib3/poolmanager.pyc in connection_from_host(self, host, port, scheme)
  76 
  77         # Make a fresh ConnectionPool of the desired type
  78         pool_cls = pool_classes_by_scheme[scheme]
  79         pool = pool_cls(host, port, **self.connection_pool_kw)
  80 
  
  KeyError: 'file'
  </code></pre>
  
  <p>The question is how can I pass a local url to <strong>requests.get</strong>?</p>
  
  <p>PS: I made up the above example. It possibly contains many errors.</p>