title: requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /api/1/
body: <p>I am trying to communicate between <code>Django</code> and <code>Python</code> file but I am getting below error :</p>
  
  <blockquote>
    <p>requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /api/1/ (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))</p>
  </blockquote>
  
  <p>I have created a Python file named <code>test.py</code> In a <code>Django</code> app and trying to communicate between them. My <code>Pytho</code>n file contains below code :</p>
  
  <pre><code>import requests
  BASE_URL='http://127.0.0.1:8000/'
  ENDPOINT='api/'
  def get_resource(id):
      resp=requests.get(BASE_URL+ENDPOINT+id+'/')
      print(resp.status_code)
      print(resp.json()) 
  id=input("Enter some ID: ")
  get_resource(id)
  </code></pre>
  
  <p><code>Models.py</code> contains:-</p>
  
  <pre><code>from django.db import models
  
  # Create your models here.
  class Employee(models.Model):
      eno=models.IntegerField()
      ename=models.CharField(max_length=70)
      esal=models.FloatField()
      eaddr=models.CharField(max_length=100)
  </code></pre>
  
  <p><code>Admin.py</code> contains:-</p>
  
  <pre><code>from django.contrib import admin
  from testapp.models import Employee
  # Register your models here.
  class EmployeeAdmin(admin.ModelAdmin):
      list_display=  ['id','eno','ename','esal','eaddr']
  
  admin.site.register(Employee,EmployeeAdmin)
  </code></pre>
  
  <p>My <code>Views.py</code> contains:-</p>
  
  <pre><code>from django.shortcuts import render
  from django.views.generic import View
  from testapp.models import Employee
  import json
  from django.http import HttpResponse
  
  
  class EmployeeDetailCBV(View):
  def get(self,request,id,*args,**kwargs):
      emp = Employee.objects.get(id=id)  
      emp_data = {'eno':emp.eno , 'ename':emp.ename , 'esal':emp.esal , 'eaddr':emp.eaddr} 
      json_data=json.dumps(emp_data)
      return HttpResponse(json_data , content_type='application/json')
  </code></pre>
  
  <p><code>urls.py</code> file contains:-</p>
  
  <pre><code>from django.contrib import admin
  from django.urls import path
  from testapp import views
  
  urlpatterns = [
      path('admin/', admin.site.urls),
      path('api/(?P&lt;id&gt;\d+)/$', views.EmployeeDetailCBV.as_view()),
  ]
  </code></pre>
  
  <p>Getting error like :</p>
  
  <blockquote>
    <p>requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=8000): Max retries exceeded with url: /api/1/ (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))</p>
  </blockquote>
  
  <p>Please help me. Thank you techies....</p>