title: python requests does not work for https from apache with wsgi
body: <p>When I try a django view that loads an external URL using requests, I get a 'module' object has no attribute 'create_connection'. However, when I use urllib2 or the same requests code from the interactive shell, it works.</p>
  
  <p>My environment:</p>
  
  <ul>
  <li>Python 2.5.2</li>
  <li>Requests 0.10.0 (I am using a 3rd party api which requires this version)</li>
  <li>Apache with WSGI inside a virtualenv for my django site</li>
  <li>Django 1.4.1</li>
  <li>Debian Linux 5</li>
  <li>I do not have SELinux (or any similar security)</li>
  </ul>
  
  <p>I actually use 2 different APIs for completely different functions. They both require requests and they both give this error:</p>
  
  <pre><code>Exception Type: AttributeError
  Exception Value: 'module' object has no attribute 'create_connection'
  Exception Location: /my/virtualenv/dir/lib/python2.5/site-packages/requests/packages/urllib3/connectionpool.py in connect, line 67
  </code></pre>
  
  <p>The mentioned line in the exception is:</p>
  
  <pre><code>sock = socket.create_connection((self.host, self.port), self.timeout)
  </code></pre>
  
  <p>It looks like the version of socket that comes with python 2.5 does not have the create_connection method (it was added in 2.6). However, I tried running the exact same code from the python interactive shell within the virtualenv and everything works. Also, requests 0.10.0 is supposed to work with python 2.5.</p>
  
  <p>I created the following 2 test views because I suspected requests to be part of the problem:</p>
  
  <pre><code>def get_requests(request):
      import requests
      r = requests.get("https://google.ca")
      return HttpResponse(r.text)
  
  def get_urllib(request):
      import urllib2
      r = urllib2.urlopen('https://google.ca')
      return HttpResponse(r.read())
  </code></pre>
  
  <p>The urllib view works, and the requests view gives me the same error as above.</p>
  
  <p>The fact that urllib works indicates to me that Apache has permission to connect to the internet (its not a firewall issue).</p>
  
  <p>I've done a tcpdump when trying the views, and requests never even attempts to connect out.</p>
  
  <p>Any ideas? Please don't suggest using something other than requests because I am using 2 different 3rd party APIs which require it.</p>
  
  <p>Thanks.</p>