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'
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.
Most helpful comment
Hey!
I would say to replace with
or if you want to keep the current way
or do
Because with the
get_listin thelist, 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'])