Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update_index results in "DisallowedHost: Invalid HTTP_HOST header: '*'" #113

Open
Krischtopp opened this issue Apr 25, 2022 · 1 comment

Comments

@Krischtopp
Copy link

I have a context processor that calls request.get_host() in my project. Calling the update_index management command results in the following exception:

django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: '*'. The domain name provided is not valid according to RFC 1034/1035.
[ERROR/MainProcess] Error updating cms using default 
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/haystack/management/commands/update_index.py", line 230, in handle
    self.update_backend(label, using)
  File "/usr/local/lib/python3.7/site-packages/haystack/management/commands/update_index.py", line 276, in update_backend
    last_max_pk=max_pk)
  File "/usr/local/lib/python3.7/site-packages/haystack/management/commands/update_index.py", line 97, in do_update
    backend.update(index, current_qs, commit=commit)
  File "/usr/local/lib/python3.7/site-packages/haystack/backends/elasticsearch_backend.py", line 168, in update
    prepped_data = index.full_prepare(obj)
  File "/usr/local/lib/python3.7/site-packages/haystack/indexes.py", line 208, in full_prepare
    self.prepared_data = self.prepare(obj)
  File "/usr/local/lib/python3.7/site-packages/aldryn_search/base.py", line 45, in prepare
    self.prepared_data['text'] = self.get_search_data(obj, current_language, request)
  File "/usr/local/lib/python3.7/site-packages/aldryn_search/search_indexes.py", line 118, in get_search_data
    plugin_text_content = self.get_plugin_search_text(base_plugin, request)
  File "/usr/local/lib/python3.7/site-packages/aldryn_search/search_indexes.py", line 134, in get_plugin_search_text
    plugin_content_bits = get_plugin_index_data(base_plugin, request)
  File "/usr/local/lib/python3.7/site-packages/aldryn_search/helpers.py", line 79, in get_plugin_index_data
    updates.update(processor(context.request))
  File "/app/context_processors.py", line 11, in host
    return {"host": request.get_host()}
  File "/usr/local/lib/python3.7/site-packages/django/http/request.py", line 111, in get_host
    raise DisallowedHost(msg)

What is the * doing in there? I can't find anything in the configuration to change this.

@DmytroLitvinov
Copy link
Contributor

DmytroLitvinov commented Dec 28, 2022

We faced the same issue recently.

UPD: In my case I got it locally when I had ALLOWED_HOSTS = ['*'].
So there is a next code in the source:

def get_request(language=None):
    """
    Returns a Request instance populated with cms specific attributes.
    """
    request_factory = RequestFactory(HTTP_HOST=settings.ALLOWED_HOSTS[0])
    request = request_factory.get("/")
    request.session = {}
    request.LANGUAGE_CODE = language or settings.LANGUAGE_CODE
    # Needed for plugin rendering.
    request.current_page = None
    request.user = AnonymousUser()
    request.toolbar = CMSToolbar(request)
    return request

In my case it took first item from ALLOWED_HOSTS which is '*'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants