Saleor: getting error while running local server: AttributeError: 'list' object has no attribute 'lower';

Created on 21 Feb 2018  Â·  4Comments  Â·  Source: mirumee/saleor

  • Error occurred while running the server
  • all dependancies installed properly.
  • created new user 'saleor' for postgre as well.
  • working on MacOS High Sierra.
ERROR django.request Internal Server Error: / [PID:6282:Thread-1]
File "/Users/purnendushukla/anaconda3/envs/saleor/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/Users/purnendushukla/anaconda3/envs/saleor/lib/python3.6/site-packages/django/utils/deprecation.py", line 93, in __call__
    response = self.process_request(request)
  File "/Users/purnendushukla/anaconda3/envs/saleor/lib/python3.6/site-packages/django/middleware/common.py", line 55, in process_request
    host = request.get_host()
  File "/Users/purnendushukla/anaconda3/envs/saleor/lib/python3.6/site-packages/django/http/request.py", line 97, in get_host
    if domain and validate_host(domain, allowed_hosts):
  File "/Users/purnendushukla/anaconda3/envs/saleor/lib/python3.6/site-packages/django/http/request.py", line 565, in validate_host
    if pattern == '*' or is_same_domain(host, pattern):
  File "/Users/purnendushukla/anaconda3/envs/saleor/lib/python3.6/site-packages/django/utils/http.py", line 273, in is_same_domain
    pattern = pattern.lower()
AttributeError: 'list' object has no attribute 'lower'

Most helpful comment

Hey!

I would say to replace with

ALLOWED_HOSTS = get_list(os.environ.get('ALLOWED_HOSTS', 'localhost,127.0.0.1'))

or if you want to keep the current way

ALLOWED_HOSTS = get_list(os.environ.get('ALLOWED_HOSTS', 'localhost')) + ['127.0.0.1']

or do

ALLOWED_HOSTS = get_list(os.environ.get('ALLOWED_HOSTS', 'localhost'))
ALLOWED_HOSTS.append('127.0.0.1')

Because with the get_list in the list, it creates a list in a list which is not the right way to do. It is creating something like [['localhost'], '127.0.0.1'] instead of ['localhost', '127.0.0.1'])

All 4 comments

Could you show us the value you set for ALLOWED_HOSTS in settings.py?
From what I see in django's source code, it would be an invalid value set in this setting.

# django/http/request.py::get_host(...)
        if settings.DEBUG and not allowed_hosts:
            allowed_hosts = ['localhost', '127.0.0.1', '[::1]']

        domain, port = split_domain_port(host)
        if domain and validate_host(domain, allowed_hosts):
            return host
# django/http/request.py
def validate_host(host, allowed_hosts):
    for pattern in allowed_hosts:
        if pattern == '*' or is_same_domain(host, pattern):
            return True
    return False
# django/utils/http.py
def is_same_domain(host, pattern):
    if not pattern:
        return False

    pattern = pattern.lower()
    return (
        pattern[0] == '.' and (host.endswith(pattern) or host == pattern[1:]) or
        pattern == host
    )

I'm a collaborator with @purnendushukla , who posted this issue.
@NyanKiyoshi the ALLOWED_HOSTS previously was this when the error occured ↓

ALLOWED_HOSTS = [ get_list(os.environ.get('ALLOWED_HOSTS', 'localhost')) , '127.0.0.1' ]

later on we changed it to :

ALLOWED_HOSTS = ['*',]

which although fixed the problem, but we are still not sure that it would be right thing to do. 🤔

Hey!

I would say to replace with

ALLOWED_HOSTS = get_list(os.environ.get('ALLOWED_HOSTS', 'localhost,127.0.0.1'))

or if you want to keep the current way

ALLOWED_HOSTS = get_list(os.environ.get('ALLOWED_HOSTS', 'localhost')) + ['127.0.0.1']

or do

ALLOWED_HOSTS = get_list(os.environ.get('ALLOWED_HOSTS', 'localhost'))
ALLOWED_HOSTS.append('127.0.0.1')

Because with the get_list in the list, it creates a list in a list which is not the right way to do. It is creating something like [['localhost'], '127.0.0.1'] instead of ['localhost', '127.0.0.1'])

thank you for the help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

timuric picture timuric  Â·  3Comments

Pacu2 picture Pacu2  Â·  3Comments

damianarechar picture damianarechar  Â·  3Comments

flaviocolonna picture flaviocolonna  Â·  3Comments

NumanIjaz picture NumanIjaz  Â·  3Comments