Same Introspect request working on Postman but not localhost

I am doing the exact same POST request to the instrospect token endpoint from:

  1. Postman - working
  2. My backend at localhost:8000 - failing with a 500 error (see below)

I think I have a settings issue in my backend client or something is breaking due to SSL or https vs. http. What could cause this error or how can I further debug it?

Client settings:

Request:

--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'token=eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJzdzczQU9zOUhZWWJmM1A2N1NOMUQtSC1HWkIxZDBlZ0RnZ0d3cjByRlNVIn0.eyJqdGkiOiI5MzExNTUwZi1jZjUwLTQyZjgtYTFjYi1hZWYzYzlmOGFiNTkiLCJleHAiOjE2MDQ0Mzk4NTIsIm5iZiI6MCwiaWF0IjoxNjA0NDM5NTUyLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvYXV0aC9yZWFsbXMvbW9iaXVzLWRldiIsImF1ZCI6ImZyb250ZW5kIiwic3ViIjoiNDA3MmFkNTEtY2YwYi00MTBiLWI2ZDEtZTM2MGM1OGIyZGQzIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoiZnJvbnRlbmQiLCJhdXRoX3RpbWUiOjAsInNlc3Npb25fc3RhdGUiOiJhYTJkYzg0OC0zYWVhLTQ0MWEtYTIwZS03ZmNmOWU4NzkxZmIiLCJhY3IiOiIxIiwiYWxsb3dlZC1vcmlnaW5zIjpbImh0dHA6Ly9sb2NhbGhvc3Q6MzAwMCJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiIsImN1c3RvbWVyIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnsiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwidmlldy1wcm9maWxlIl19fSwic2NvcGUiOiJvcGVuaWQgZW1haWwgcHJvZmlsZSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJuYW1lIjoiTWFyZ2FyZXQgVXBzaHVyIiwicHJlZmVycmVkX3VzZXJuYW1lIjoibWFyZ2FyZXQrdGVzdDEiLCJnaXZlbl9uYW1lIjoiTWFyZ2FyZXQiLCJmYW1pbHlfbmFtZSI6IlVwc2h1ciIsImVtYWlsIjoibWFyZ2FyZXQrdGVzdDFAbW9iaXVzbWF0ZXJpYWxzLmNvbSJ9.MQ3HZJJyww4if2TkoVNFsgWt4wg3jJ_vDm9oIroAZio9bPBk5_NQAig8fWf2JzOpBpFv878jeRT9lMm60_pvmyQ6UkUK7O9YK2Li4RXyglRJ47k_moDHFOqy2tLqUtzpnCFAWzas_iGvaoddPac7TTC98jk2y2en_Zs-7zzomS2uhpMktCHlqqfAm5cpGi8CbfqkCIx-v548TLJeLpxoD3dfNiGOuQscjlV8_hn11MgAmGqW1bhLtmyMsBySd60_Dk61rFuGLbJZMQbbntHap2y1DjbxBeee-12-2dVnAd8CWR85BDn0_mIRbI4Vh-kXLDmrcCbgIhbtOWN3U0Nxug' \
--data-urlencode 'client_secret=SECRET' \
--data-urlencode 'client_id=backend'

Error:

web_1  |     response = get_response(request)
web_1  |   File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 169, in _get_response
web_1  |     response = middleware_method(request, callback, callback_args, callback_kwargs)
web_1  |   File "/app/django-keycloak-auth/middleware.py", line 102, in process_view
web_1  |     if not self.keycloak.is_token_active(token):
web_1  |   File "/app/django-keycloak-auth/keycloak.py", line 121, in is_token_active
web_1  |     introspect_token = self.introspect(token)
web_1  |   File "/app/django-keycloak-auth/keycloak.py", line 108, in introspect
web_1  |     response = requests.request("POST", self.token_introspection_endpoint, data=payload, headers=headers)
web_1  |   File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 61, in request
web_1  |     return session.request(method=method, url=url, **kwargs)
web_1  |   File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
web_1  |     resp = self.send(prep, **send_kwargs)
web_1  |   File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
web_1  |     r = adapter.send(request, **kwargs)
web_1  |   File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
web_1  |     raise ConnectionError(e, request=request)
web_1  | requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /auth/realms/mobius-dev/protocol/openid-connect/token/introspect (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f493c716130>: Failed to establish a new connection: [Errno 111] Connection refused'))

I figured this out - My docker localhost and my actual localhost were conflicting. So the keycloak server was allowing requests from the regular host but not the docker localhost. Putting all the services on the same docker container solved the problem