title: How to GET external url inside django views
body: <p>I'm trying to get some page to parse its json content from within a views, using <a href="https://docs.python.org/2/howto/urllib2.html" rel="nofollow">urllib2</a>.</p>
  
  <p>Here is what I tried:</p>
  
  <pre><code>from django.http import JsonResponse
  import urllib2
  
  def someviews(request):
      url = some_external_url
      req = urllib2.Request(url)
      response = urllib2.urlopen(req)
      the_page = response.read()
      return the_page.content
  </code></pre>
  
  <p>However, I get <code>HTTP Error 502: Bad Gateway</code> at </p>
  
  <pre><code>response = urllib2.urlopen(req) 
  </code></pre>
  
  <p>What could be wrong here, and how can I fix it?</p>