Forums

Error during 'Deploy!' part of tutorial-- "Invalid HTTP_HOST header"

I get to the very end of this part of the tutorial, reload the web page and load it, and receive this error:

DisallowedHost at /Invalid HTTP_HOST header: 'simonsterj.pythonanywhere.com'. You may need to add 'simonsterj.pythonanywhere.com' to ALLOWED_HOSTS.

I've used my own names for the databases/virtual environments so I've double/triple checked that I didn't make any mistakes when typing out paths.
I've also tried updating 'ALLOWED_HOSTS' in my local computer as suggested, pushed it to GitHub, and pulled it to the live server using the PythonAnywhere console. Still same error.
What could be the issue?

edit: typo

Did you reload you web app after pulling to PythonAnywhere?

I did.

Now that I remember, I did skip ONE step when following the tutorial again for pushing/pulling: I skipped the 'git remote add origin' command as I thought this was only necessary once. Should I have executed this command before 'git push -u origin master'?

edit: if it makes any difference--I am using pyenv on my local computer, and virtualenv on the PythonAnywhere console. I can't think of anything else that I'm doing differently and messing up :/ please help!

It seems likely that, if you haven't set up git correctly, then pushing and pulling code is unlikely to work the way you expect. Did you check that the code was what you expected after the push?

I checked that the changes were made and correct on github, but cannot find a way to make sure that it was updated onto PythonAnywhere.
The last time I gitcloned on the PA's bash, I received the message:

fatal: destination path 'dg-blog' already exists and is not an empty directory.

And as a matter of fact, I was just now going through a git tutorial. I do believe I had it set up correctly. What else might I try?

edit: Also, then would it be safe to assume that the fix to the error is in fact the need to add 'simonsterj.pythonanywhere.com' into the 'ALLOWED_HOSTS' list in settings.py?
This was not mentioned in the tutorial.

edit2: Is all that it takes to 'pull' into PA simply the 'git clone' command while in my venv? Or should I have not been in a venv as is implied by the order within the tutorial?

You can look at your files in Files tab or you can use an editor in a bash console to look at them.

Yes, it is necessary to set ALLOWED_HOSTS correctly.

you were right all along. I had not been using the correct git commands to update it onto PA. Got it to work. Thank you glenn!

Im having same issue , guys

I checked the error log and this was the error: Invalid HTTP_HOST header: 'community.pythonanywhere.com'. You may need to add 'community.pythonanywhere.com' to ALLOWED_HOSTS.

How do i go about it? someone please help

Sorry for the slow response! What setting do you have for ALLOWED_HOSTS in your settings.py file?

I am receiving the same error: Invalid HTTP_HOST header: 'route2sabya.pythonanywhere.com'. You may need to add 'route2sabya.pythonanywhere.com' to ALLOWED_HOSTS. Can anybody kindly tell us how to resolve this issue.

you should go to settings.py and add route2sabya.pythonanywhere.com to the allowed_hosts variable (and then reload your webapp)

I had the same error, so I added bakagaijinhakka.pythonanywhere.com to my ALLOWED_HOSTS. Now it returns me the following errors

2017-04-10 14:27:32,716 :Error running WSGI application
2017-04-10 14:27:32,717 :ImportError: No module named 'bakagaijinhakka'
2017-04-10 14:27:32,717 :  File "/var/www/bakagaijinhakka_pythonanywhere_com_wsgi.py", line 13, in <module>

I had the same error, so I added bakagaijinhakka.pythonanywhere.com to my ALLOWED_HOSTS. Now it returns me the following errors

2017-04-10 14:27:32,716 :Error running WSGI application
2017-04-10 14:27:32,717 :ImportError: No module named 'bakagaijinhakka'
2017-04-10 14:27:32,717 :  File "/var/www/bakagaijinhakka_pythonanywhere_com_wsgi.py", line 13, in <module>

Hi there,

The full error message is something like this:

2017-04-10 14:47:58,650 :Error running WSGI application
2017-04-10 14:47:58,662 :ImportError: No module named 'bakagaijinhakka'
2017-04-10 14:47:58,662 :  File "/var/www/bakagaijinhakka_pythonanywhere_com_wsgi.py", line 13, in <module>
2017-04-10 14:47:58,662 :    application = DjangoWhiteNoise(get_wsgi_application())
2017-04-10 14:47:58,662 :
2017-04-10 14:47:58,662 :  File "/home/BakaGaijinHakka/tutorial/myvenv/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2017-04-10 14:47:58,662 :    django.setup(set_prefix=False)
2017-04-10 14:47:58,663 :
2017-04-10 14:47:58,663 :  File "/home/BakaGaijinHakka/tutorial/myvenv/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
2017-04-10 14:47:58,663 :    apps.populate(settings.INSTALLED_APPS)
2017-04-10 14:47:58,663 :
2017-04-10 14:47:58,663 :  File "/home/BakaGaijinHakka/tutorial/myvenv/lib/python3.5/site-packages/django/apps/registry.py", line 85, in populate
2017-04-10 14:47:58,663 :    app_config = AppConfig.create(entry)
2017-04-10 14:47:58,663 :
2017-04-10 14:47:58,663 :  File "/home/BakaGaijinHakka/tutorial/myvenv/lib/python3.5/site-packages/django/apps/config.py", line 120, in create
2017-04-10 14:47:58,664 :    mod = import_module(mod_path)
2017-04-10 14:47:58,664 :***************************************************
2017-04-10 14:47:58,664 :If you're seeing an import error and don't know why,
2017-04-10 14:47:58,664 :we have a dedicated help page to help you debug: 
2017-04-10 14:47:58,664 :https://help.pythonanywhere.com/pages/DebuggingImportError/
2017-04-10 14:47:58,664 :***************************************************

What do you see if you follow the instructions on the linked help page?

it's

go to files and edit settings.py -> ALLOWED_HOSTS = ['*']

Hei there is this problem solved?

What problem? There are a number of issues discussed here and, as far as I can see, they are all answered.

Is it necessary to again push code to GitHub and pull to live server after updating allowed hosts? Just setting allowed hosts correctly won't do?

you need to update allowed_hosts on the live server, however it is that you do it.

I had the same problem and I was able to pass around it in the following way, what you need to do is just to add the same name that you see in the error message in the settings.py but you have to pass through Files and you will find something like this : ALLOWED_HOSTS = ['thename.pythonanywhere.com'], after this you should be able to view the site online! good luck

hello friend...plz try putting this with in quotes like this in settings file....ALLOWED_HOSTS = [ 'thename.pythonanywhere.com' ]... it is working...!!!

Invalid HTTP_HOST header: 'test.pythonanywhere.com'. You may need to add 'test.pythonanywhere.com' to ALLOWED_HOSTS. to resolve this issue go to the setting you can see this ALLOWED_HOSTS example below ALLOWED_HOSTS [] ALLOWED_HOSTS ['test.pythonanywhere.com'] then save it will work

sir i received same problem of disallowed hosts and then something went wrong

I see that you emailed us about this too; the important thing, from the error message that you were getting, is to remember to put quotes around the hostname in ALLOWED_HOSTS.

[SOLVED] for Django 3.0.3

[This problem is occurred because of forgetting to add the host name in ALLOWED_HOSTS list in settings.py]

Go To >>pythoneverywhere.com Then Go to >>Files Then open your project directory and go through your settings.py file

Then you might see >> ALLOWED_HOSTS = [] Add your host name in this list >> ALLOWED_HOSTS = ['yourdomain.pythonanywhere.com']

I even added host name in the ALLOWED_HOSTS in the settings.py and reloaded but still facing the same issue

Are you sure it's exactly the same issue? I see a "not found" error when I visit your website, which suggests that you don't have a view defined for the / URL.

Hi, I have the same problem. I checked a couple of times: In the settings.py ALLOWED_HOSTS has the right value. But somehow the server doesn't read the updated settings.py. In the error notice it says, that only a local host is allowed. I changed the settings.py again locally, pushed it, pulled it to Pythonanywhere - nothing changed. I still get the error message. How can I get the server to read the updated settings.py?

What, exactly have you set ALLOWED_HOSTS to? and have you reloaded your web app since changing the code?

Hey, I have the same problem. I have added 'gayathrivijay212.pythonanywhere.com' to my ALLOWED_HOSTS lists but the error still persists. can somebody pls help me out ?

Did you reload the web app after making those changes?