无效的HTTP_HOST标头:提供的域名无效-使用容器名称的dockerized django应用请求

时间:2018-10-25 20:23:25

标签: django docker flask docker-compose

在一个由多个通过docker-compose运行的微服务组成的应用程序中,我需要一种方法来从一个容器(通过烧瓶和请求/** Drawing an ellipse in the Canvas * @param {CanvasRenderingContext2D} ctx * @param {number} cx abscissa * @param {number} cy ordinate * @param {number} rx radius * @param {number} ry vertical radius * @param {number} angle the angle on degrees of the ellipse from the horizontale * @param {string} style Colour of the shape */ function ellipse(ctx, cx, cy, rx, ry, angle, style) { ctx.save(); // save the initial context ctx.beginPath(); ctx.translate(cx, cy); ctx.rotate(angle * Math.PI / 180); ctx.scale(rx, ry); ctx.arc(0, 0, 1, 0, 2 * Math.PI, false); ctx.restore(); // restore the original state of the context ctx.save(); if (style) { ctx.strokeStyle = style; } ctx.stroke(); ctx.restore(); } function Flower() { let i = 0; while (i < 10) { ellipse(ctx, 300, 300, 200, 40, 30 * i, 'red'); i++; } })直接向另一个容器(app / django):

这是我正在尝试的简化版本。

routes.py:

chart

我得到的响应是一条错误消息:

@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

我可以毫无问题地向其他运行flask应用程序的容器发出这种请求。我无法控制我们是否为此特定微服务使用Django。

这似乎是因为主机名中带有下划线:see this post。有没有解决的办法?似乎必须可以在容器之间进行简单的请求。

1 个答案:

答案 0 :(得分:3)

在docker-compose文件中,修改服务名称,以避免在Django服务中使用下划线。

这是避免错误的唯一途径,因为它不是Docker限制,而是Django问题。