Re: Error: TemplateSyntaxError: Caught SuspiciousOperation while rendering: Invalid HTTP_HOST header

302 views
Skip to first unread message

Christian Hammond

unread,
May 24, 2013, 4:28:12 AM5/24/13
to revie...@googlegroups.com
Hi,

If ALLOWED_HOSTS is not set, you shouldn't see this, unless you're accessing it with a domain that Django doesn't consider to be a validly formed domain. It will first check the "Host:" header (as sent by the client) and, if that's missing, the server name as reported by mod_wsgi.

It would help to know what the actual URL is that you're accessing. Also, the server name as reported by the server.

Try removing the ALLOWED_HOSTS setting, and then doing this:

    $ rb-site manage /path/to/site shell
    >>> from django.conf import settings
    >>> print settings.ALLOWED_HOSTS

That will just confirm that we're using the proper default.

Christian

--
Christian Hammond - chi...@chipx86.com
Review Board - http://www.reviewboard.org


On Thu, May 23, 2013 at 7:10 PM, Ryan Guilbault <rguil...@meditech.com> wrote:
Hello :-

I recently installed ReviewBoard on a Windows Server 28 R2 Datacenter (x64) machine from:

ReviewBoard-1.6.16-py2.7.egg

I'm using the 32-bit Python 2.7 (r27:82525) and the dependencies installed from easy_install ReviewBoard, e.g.:

django_evolution-0.6.9-py2.7.egg
django-1.3.7-py2.7.egg
Djblets-0.6.28-py2.7.egg
python_dateutil-1.5-py2.7.egg
MySQL_python-1.2.4-py2.7-win32.egg

I'm using Apache 2.2.22 with mod_wsgi (which was built and installed by someone else) and my configuration from 'rb-site install' looks like:

<VirtualHost *:80>
    ServerName server.example.com
    DocumentRoot "E:/ReviewBoard/htdocs"

    # Error handlers
    ErrorDocument 500 /errordocs/500.html

    WSGIPassAuthorization On
    WSGIScriptAlias "/rb" "E:/ReviewBoard/htdocs/reviewboard.wsgi/rb"

    <Directory "E:/ReviewBoard/htdocs">
        AllowOverride All
        Options -Indexes +FollowSymLinks
        Allow from all
    </Directory>

    # Alias static media requests to filesystem
    Alias /rb/media "E:/ReviewBoard/htdocs/media"
    Alias /rb/errordocs "E:/ReviewBoard/htdocs/errordocs"
    Alias /rb/favicon.ico "E:/ReviewBoard/htdocs/media/rbcommons/images/favicon.png"
</VirtualHost>

when I attempt to access the WebUI from the remote host location, I get an internal server error (HTTP 500), which is logged in Apache as:

mod_wsgi (pid=2080): Exception occurred processing WSGI script 'E:/ReviewBoard/htdocs/reviewboard.wsgi'.
  File "C:\\Python27\\lib\\site-packages\\django-1.3.7-py2.7.egg\\django\\core\\handlers\\wsgi.py", line 272, in __call__
    response = self.get_response(request)
...
  File "C:\\Python27\\lib\\site-packages\\django-1.3.7-py2.7.egg\\django\\http\\__init__.py", line 179, in get_host
    "Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): %s" % host)
TemplateSyntaxError: Caught SuspiciousOperation while rendering: Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): server.example.com

Note: I can access ReviewBoard's WebUI just fine from the machine via http://localhost/rb/; the error only occurs when I access it remotely, e.g. http://server.example.com/rb/

Most of this technology is new to me (python, django, anything beyond basic apache management), so I've been spending a lot of time trying to wrap my mind around the issue -- I tried adding:

ALLOWED_HOSTS = ['*']

to E:\ReviewBoard\conf\settings_local.py, but the error persists and I'm out of ideas. Note: due to localhost working, part of me believes there must be a configuration setting somewhere that refers to localhost, instead of the fully qualified server name, but I have been unable to find any such references to localhost.

Does anybody have any suggestions on what I can try next?

thanks

--
Want to help the Review Board project? Donate today at http://www.reviewboard.org/donate/
Happy user? Let us know at http://www.reviewboard.org/users/
-~----------~----~----~----~------~----~------~--~---
To unsubscribe from this group, send email to reviewboard...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/reviewboard?hl=en
---
You received this message because you are subscribed to the Google Groups "reviewboard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reviewboard...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ryan Guilbault

unread,
May 24, 2013, 10:57:29 AM5/24/13
to revie...@googlegroups.com, chi...@chipx86.com
interestingly, after removing ALLOWED_HOSTS and even switching back to DEBUG = False, I'm getting back:

['*']

from running the lines you recommended. here is my settings_local.py file:

# Site-specific configuration settings for Review Board
# Definitions of these settings can be found at
# http://docs.djangoproject.com/en/dev/ref/settings/

# Database configuration
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'reviewboard',
        'USER': 'reviewBoardUser',
        'PASSWORD': <redacted>,
        'HOST': 'localhost',
        'PORT': '',
    },
}

# Unique secret key. Don't share this with anybody.
SECRET_KEY = <redacted>

# Cache backend settings.
CACHE_BACKEND = 'memcached://localhost:11211/'

# Extra site information.
SITE_ID = 1
SITE_ROOT = '/rb/'
FORCE_SCRIPT_NAME = ''
DEBUG = False

Here is the HTTP communication as reported from the browser:

  1. Request URL:
  2. Request Method:
    GET
  3. Status Code:
    500 INTERNAL SERVER ERROR
  4. Request Headersview source
    1. Accept:
      text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    2. Accept-Charset:
      ISO-8859-1,utf-8;q=0.7,*;q=0.3
    3. Accept-Encoding:
      gzip,deflate,sdch
    4. Accept-Language:
      en-US,en;q=0.8
    5. Cache-Control:
      no-cache
    6. Connection:
      keep-alive
    7. Host:
    8. Pragma:
      no-cache
    9. User-Agent:
      Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
  5. Response Headersview source
    1. Connection:
      close
    2. Content-Language:
      en-us
    3. Content-Length:
      526
    4. Content-Type:
      text/html; charset=utf-8
    5. Date:
      Fri, 24 May 2013 14:50:21 GMT
    6. Server:
      Apache/2.2.22 (Win32) mod_wsgi/3.5-BRANCH Python/2.7
    7. Vary:
      Accept-Language

I had substituted server.example.com in my prior post in place of atg_wpltools.meditech.com (i.e. the error is the same as previously reported). I have tried different permutations of ALLOWED_HOSTS, including: ['.meditech.com'], ['atg_wpltools.meditech.com'] and ['*'].

Christian Hammond

unread,
May 24, 2013, 2:58:49 PM5/24/13
to revie...@googlegroups.com
The reason is that "_" is not valid in hostnames. Django sees that and assumes something bad is happening.

Christian

--
Christian Hammond - chi...@chipx86.com
Review Board - http://www.reviewboard.org
Beanbag, Inc. - http://www.beanbaginc.com


Ryan Guilbault

unread,
May 24, 2013, 3:03:49 PM5/24/13
to revie...@googlegroups.com
I would never have guessed that. ever!

let me see what I can do to maybe rename this machine and see if the issue is cleared up.

thank you much for your insight!!


You received this message because you are subscribed to a topic in the Google Groups "reviewboard" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/reviewboard/Q9zxFFiuBe0/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to reviewboard...@googlegroups.com.

Ryan Guilbault

unread,
May 25, 2013, 2:27:38 PM5/25/13
to revie...@googlegroups.com, chi...@chipx86.com
removing the underscore solved my issue -- thank you, again!
Reply all
Reply to author
Forward
0 new messages