[Django] #33065: DisallowedHost exception when using server/container name to access django service

6 views
Skip to first unread message

Django

unread,
Aug 27, 2021, 5:25:51 PM8/27/21
to django-...@googlegroups.com
#33065: DisallowedHost exception when using server/container name to access django
service
-----------------------------------------+------------------------
Reporter: ziyunxiao | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Hello,

I am using the Django rest framework to provide REST API to other
services.

All services have been packaged in docker. and all services are sharing
data via the docker network.

Let's say, App A is calling App B(Django) APIs.

because they are on the same docker network then App A can call it like
HTTP://server_B_container_name:8000/api/
But I got a DisallwedHost exception. The error message likes this:
"Invalid HTTP_HOST header: 'training_api'. The domain name provided is not
valid according to RFC 1034/1035."

I have set the settings like this.
DJANGO_ALLOWED_HOSTS=localhost,training_api,*

It works if I call it through localhost or fully qualified domain
name(port 8000 is exposed to host).

How can I call the Django via container name, not the IP? the IP will
change every time it starts.

Thanks,
Robin

--
Ticket URL: <https://code.djangoproject.com/ticket/33065>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 27, 2021, 5:29:02 PM8/27/21
to django-...@googlegroups.com
#33065: DisallowedHost exception when using server/container name to access django
service
-------------------------------+--------------------------------------

Reporter: ziyunxiao | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by ziyunxiao:

Old description:

> Hello,
>
> I am using the Django rest framework to provide REST API to other
> services.
>
> All services have been packaged in docker. and all services are sharing
> data via the docker network.
>
> Let's say, App A is calling App B(Django) APIs.
>
> because they are on the same docker network then App A can call it like
> HTTP://server_B_container_name:8000/api/
> But I got a DisallwedHost exception. The error message likes this:
> "Invalid HTTP_HOST header: 'training_api'. The domain name provided is
> not valid according to RFC 1034/1035."
>
> I have set the settings like this.
> DJANGO_ALLOWED_HOSTS=localhost,training_api,*
>
> It works if I call it through localhost or fully qualified domain
> name(port 8000 is exposed to host).
>
> How can I call the Django via container name, not the IP? the IP will
> change every time it starts.
>
> Thanks,
> Robin

New description:

Hello,

I am using the Django rest framework to provide REST API to other
services.

All services have been packaged in docker. and all services are sharing
data via the docker network.

Let's say, App A is calling App B(Django) APIs.

because they are on the same docker network then App A can call it like
HTTP://server_B_container_name:8000/api/
But I got a DisallwedHost exception. The error message likes this:
"Invalid HTTP_HOST header: 'training_api'. The domain name provided is not
valid according to RFC 1034/1035."

I have set the settings like this.
DJANGO_ALLOWED_HOSTS=localhost,training_api,*

It works if I call it through localhost on the host, or container IP
inside App A container or a fully qualified domain name of the host(port
8000 is exposed to host) from other machines.

How can I call the Django via container name from App A, not the IP? the


IP will change every time it starts.

Thanks,
Robin

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33065#comment:1>

Django

unread,
Aug 27, 2021, 5:57:50 PM8/27/21
to django-...@googlegroups.com
#33065: DisallowedHost exception when using server/container name to access django
service
-------------------------------+--------------------------------------
Reporter: ziyunxiao | Owner: nobody
Type: Uncategorized | Status: closed
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Comment:

Please see TicketClosingReasons/UseSupportChannels for ways to get help
with usage questions.

--
Ticket URL: <https://code.djangoproject.com/ticket/33065#comment:2>

Reply all
Reply to author
Forward
0 new messages