title: Unable to call Django REST API from within the same AWS EC2 Linux machine
body: <p>I am working on a Django REST Framework web application, for that I have a Django server running in an AWS EC2 Linux box at a particular IP:PORT. There are URLs (APIs) which I can call for specific functionalities.</p>
  
  <p>In Windows machine as well as in other local Linux machine (not AWS EC2) I am able to call those APIs successfully and getting the desired results perfectly.</p>
  
  <p>But the problem is when I am trying to call the APIs from within the same EC2 Linux box.</p>
  
  <p>A simple code I wrote to test the call of one API from the same AWS EC2 Linux box:</p>
  
  <pre><code>import requests
  
  vURL = 'http://&lt;ipaddress&gt;:&lt;port&gt;/myapi/'
  vSession = requests.Session()
  vSession.headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
  vResponse = vSession.get(vURL)
  
  if vResponse.status_code == 200:
     print('JSON: ', vResponse.json())
  else:
     print('GET Failed: ', vResponse)
  
  vSession.close()
  </code></pre>
  
  <p>This script is returning <code>GET Failed: &lt;Response [403]&gt;</code>.</p>
  
  <p>In one thing I am sure that there is no authentication related issues in the EC2 instance because using this same script I got actual response in other local Linux machines (not AWS EC2) and also in Windows machine.</p>
  
  <p>It seems that the calling of the API <em>(which includes the same IP:PORT of the same AWS EC2 machine)</em> from the same machine is somehow getting restricted by either the security policies of AWS or firewall or something else.</p>
  
  <p>May be I have to do some changes in <strong>setting.py</strong>. Though I have incorporated all the required settings as per my knowledge in the <code>settings.py</code>, like:</p>
  
  <ul>
  <li><code>ALLOWED_HOST</code></li>
  <li><code>CORS_ORIGIN_WHITELIST</code></li>
  <li>Mentioning <code>corsheaders</code> in <code>INSTALLED_APPS</code> list</li>
  <li>Mentioning <code>corsheaders.middleware.CorsMiddleware</code> in <code>MIDDLEWARE</code> list</li>
  </ul>
  
  <p>For example, below are the CORS settings that I have incorporated in the <code>setting.py</code>:</p>
  
  <pre><code>CORS_ORIGIN_ALLOW_ALL = True
  CORS_ALLOW_CREDENTIALS = True
  CORS_ALLOW_METHODS = ('GET', 'PUT', 'POST', 'DELETE')
  CORS_ORIGIN_WHITELIST = (
     &lt; All the IP address that calls this
       application are listed here,
       this list includes the IP of the
       AWS EC2 machine also &gt;
  )     
  </code></pre>
  
  <p>Does anyone have any ideas regarding this issue? Please help me to understand the reason of this issue and how to fix this. </p>
  
  <p>Thanks in advance.</p>