I am trying to communicate between `Django` and `Python` file but I am getting below error :

> 
> 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'))
> 
> 
> 

I have created a Python file named `test.py` In a `Django` app and trying to communicate between them. My `Pytho`n file contains below 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)

```

`Models.py` contains:-

```
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)

```

`Admin.py` contains:-

```
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)

```

My `Views.py` contains:-

```
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')

```

`urls.py` file contains:-

```
from django.contrib import admin
from django.urls import path
from testapp import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/(?P<id>\d+)/$', views.EmployeeDetailCBV.as_view()),
]

```

Getting error like :

> 
> 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'))
> 
> 
> 

Please help me. Thank you techies....