Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid HTTP_HOST header: The domain name provided is not valid -- requests to dockerized django app using container name

Within an app composed of multiple microservices run via docker-compose, I need a way to make a request from one container (app via flask & requests), directly to the other (chart/django):

This is a simplified version of what I'm attempting.

routes.py:

@APP.route('/post_data', methods=['POST'])
def post_data():
  post_data = request.get_json()
  response = requests.post('http://chart_app_1:8080/json/', data=post_data)
  return response.text

The response I get is an error message:

django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'chart_app_1:8080'. The domain name provided is not valid according to RFC 1034/1035

I'm able to make exactly this kind of request to other containers running flask apps, with no problems. I don't have any control over whether or not we use Django for this particular microservice though.

It seems that this might be because the hostname has an underscore in it: see this post. Is there a way around this? It seems like it must be possible to make a simple request between containers.

like image 211
ebbishop Avatar asked Oct 25 '18 20:10

ebbishop


1 Answers

In the docker-compose file, modify the service name for avoiding underscores in the Django service.

That's the only way that I know for avoiding the error as it's not a Docker limitation.

like image 173
Andrés Cidoncha Carballo Avatar answered Oct 22 '22 15:10

Andrés Cidoncha Carballo