'Django : Max retries exceeded with url: /o/token/ [Errno 11001] getaddrinfo failed

Hey guys I'm creating a multi-tenant app using DJANGO TENANTS and DRF

I'm trying to create a login api using the following function

login api-view

@api_view(['POST'])
@permission_classes([permissions.AllowAny])
def login(request):

    restaurant_name = request.POST.get('restaurant_name')
    email = request.POST.get('email')
    password = request.POST.get('password')

    restaurant_schema = restaurant_name

    if not restaurant_name:
        restaurant_schema = 'public'
        domain_name = 'http://localhost:8000/o/token/'

    else:
        domain_name = 'http://' + restaurant_name + '.localhost:8000/o/token/'

    

    with schema_context(restaurant_schema):
        # c = Client.objects.get(name='BFC')

        # return Response(c.reverse(request,'test'))

        app = Application.objects.first()

        r = requests.post(domain_name,
                          data={
                              'grant_type': 'password',
                              'username': email,
                              'password': password,
                              'client_id': app.client_id,
                              # 'scope': 'read',
                              'client_secret': app.client_secret,
                          },)

    return Response(r.json())

But I'm getting this error:

HTTPConnectionPool(host='bfc.localhost', port=8000): Max retries exceeded with url: /o/token/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001E24200D600>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

I have tried to check the connection using:

socket.create_connection(('localhost',8000),timeout=2)

and

socket.create_connection(('bfc.localhost',8000),timeout=2)

bfc.localhost cant create a connection yet localhost and also I can access the domain from my browser

Additional info:

In Postman OAuth 2 section I can get a response with the same fields

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source