Django + Django Tenants + DRF API = http: error: gaierror: [Errno 11001] getaddrinfo failed

148 views Asked by At

Can someone please help to resolve the error i am getting?

I am using django-tenants package with DRF REST API

The issue is that accessing API VIEW via browser works fine, for example:

http://demo.localhost:9000/api/zakaz

But sending requests to this address via "requests" gives the error:

HTTPConnectionPool(host='demo.localhost', port=9000): Max retries exceeded with url: /api/zakaz/3/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000017E1D9FEB00>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

Similarly and PING or HTTPIE request from console even to basic address "demo.localhost:9000" gives the same:

http http://demo.localhost:9000/                 

http: error: gaierror: [Errno 11001] getaddrinfo failed
Couldn’t resolve the given hostname. Please check the URL and try again.

Meaning that this address is only resolved in browser, but not from Django or Python console..

What am i doing wrong? How do i send api request in django-tenants separately for each tenant?

I have added rest framework to TENANT APPS:

TENANT_APPS = (
    # your tenant-specific apps
    'rest_framework',
    'api.apps.ApiConfig',
    'orders.apps.OrdersConfig',
    'patients.apps.PatientsConfig',
)
1

There are 1 answers

1
Евгений On

I spent almost 8 hours to fix it and now - i got the issue - for some reason browser resolves wildcard subdomains from address string, but Windows fails to do so for pycharm and python..

I have edited the HOSTS file adding the subdomains

127.0.0.1 demo.localhost
127.0.0.1 revital.localhost
127.0.0.1 localhost

And guess what? API and everything WORKS as expected...

Basically for localhost development i will have to add all possible tenant subdomains...

How do i deal with tenant wildcard subdomains in Django and not just list them in HOSTS file?

Any ideas / working solutions?

Does this happen with Linux distros?