Link to home
Start Free TrialLog in
Avatar of coder
coderFlag for Australia

asked on

browser error Refused to connect to web application while the ports are open

Hi expertsUser generated image,

   My web application is running on aws ubuntu 16.  I have the following ports open from aws.  
It has the following applications running on ubuntu

uwsgi with nginx -  i  Think it uses port 80
node.js with react - react is rendering on port 9009
webpack with webpack.config.js - which creates js file which will be using port 80
npm run django: runserver 0.0.0.0:8000  uses port 8000
elastic search :9200 uses port 9200
postgresql used port:5432

Please see the opened ports on aws.  screenshot for reference.

With putty I connect to linux ubuntu machine with the following ip address 54.252.92.17

There is docker application which runs inside that linux box uses nginx, postgres, elasticsearch

When I run docker application, and I able to see from browser with http://54.252.92.17/

Where as when I run python manage.py runserver 0.0.0.0:8000 I am not able to see the application.

The site can't be reached 54.252.92.17 refused to connect error.

Whereas I can see the docker application when the docker is run.

Please help me why the python application is not running on the browser, where as Docker application runs well.

With python manage.py runserver 0,0,0,0:8000 I am running from the source code.  Whereas with docker I am running the docker image.

Both are same application.  

Please help me in fixing this issue.

with many thanks,
Bharath AK
Avatar of Phil Phillips
Phil Phillips
Flag of United States of America image

For the python app, have you tried connecting directly like http://54.252.92.17:8000 ? Seems like the command is set up to have it listen on port 8000.
Avatar of coder

ASKER

Hi Phillips,

      I had tried http://54.*.*.*:8000

When I run python manage.py runserver 0.0.0.0:8000 I get the following error.

I got some other errors please see the errors below

Django version 1.11.1, using settings 'ntdl.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Internal Server Error: /
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.6/dist-packages/django/utils/deprecation.py", line 138, in __call__
    response = self.process_request(request)
  File "/usr/local/lib/python3.6/dist-packages/django/middleware/security.py", line 25, in process_request
    host = self.redirect_host or request.get_host()
  File "/usr/local/lib/python3.6/dist-packages/django/http/request.py", line 105, in get_host
    if domain and validate_host(domain, allowed_hosts):
  File "/usr/local/lib/python3.6/dist-packages/django/http/request.py", line 579, in validate_host
    if pattern == '*' or is_same_domain(host, pattern):
  File "/usr/local/lib/python3.6/dist-packages/django/utils/http.py", line 291, in is_same_domain
    pattern = pattern.lower()
AttributeError: 'ellipsis' object has no attribute 'lower'
"GET / HTTP/1.1" 500 11970
Internal Server Error: /favicon.ico
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.6/dist-packages/django/utils/deprecation.py", line 138, in __call__
    response = self.process_request(request)
  File "/usr/local/lib/python3.6/dist-packages/django/middleware/security.py", line 25, in process_request
    host = self.redirect_host or request.get_host()
  File "/usr/local/lib/python3.6/dist-packages/django/http/request.py", line 105, in get_host
    if domain and validate_host(domain, allowed_hosts):
  File "/usr/local/lib/python3.6/dist-packages/django/http/request.py", line 579, in validate_host
    if pattern == '*' or is_same_domain(host, pattern):
  File "/usr/local/lib/python3.6/dist-packages/django/utils/http.py", line 291, in is_same_domain
    pattern = pattern.lower()
AttributeError: 'ellipsis' object has no attribute 'lower'
"GET /favicon.ico HTTP/1.1" 500 11967


Please help me how to fix this error.

With Many thanks,
Bharath AK
Avatar of coder

ASKER

Hi Scott

      Thankyou,

With Kind Regards,
Bharath AK
SOLUTION
Avatar of Phil Phillips
Phil Phillips
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of coder

ASKER

Hi Phill,

       I had checked the config inside /usr/bin/python-config and also inside my bin/python-config, and searched for ... in that file
but ... text is not all available in python-config file.  Do I have check for any other file?

With Many Thanks,
Bharath AK
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of coder

ASKER

Hi Phill

I had checked the following files manually opening and checking it

root@ip-10-252-14-11:/home/ubuntu/workarea/sourcecode/ntdl# python3 manage.py runserver 0.0.0.0:80
Performing system checks...

System check identified no issues (0 silenced).
March 21, 2018 - 17:59:58
Django version 1.11.1, using settings 'ntdl.settings'
Starting development server at http://0.0.0.0:80/
Quit the server with CONTROL-C.
Internal Server Error: /
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.6/dist-packages/django/utils/deprecation.py", line 138, in __call__
    response = self.process_request(request)
  File "/usr/local/lib/python3.6/dist-packages/django/middleware/security.py", line 25, in process_request
    host = self.redirect_host or request.get_host()
  File "/usr/local/lib/python3.6/dist-packages/django/http/request.py", line 105, in get_host
    if domain and validate_host(domain, allowed_hosts):
  File "/usr/local/lib/python3.6/dist-packages/django/http/request.py", line 579, in validate_host
    if pattern == '*' or is_same_domain(host, pattern):
  File "/usr/local/lib/python3.6/dist-packages/django/utils/http.py", line 291, in is_same_domain
    pattern = pattern.lower()
AttributeError: 'ellipsis' object has no attribute 'lower'
"GET / HTTP/1.1" 500 12110
Internal Server Error: /favicon.ico
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.6/dist-packages/django/utils/deprecation.py", line 138, in __call__
    response = self.process_request(request)
  File "/usr/local/lib/python3.6/dist-packages/django/middleware/security.py", line 25, in process_request
    host = self.redirect_host or request.get_host()
  File "/usr/local/lib/python3.6/dist-packages/django/http/request.py", line 105, in get_host
    if domain and validate_host(domain, allowed_hosts):
  File "/usr/local/lib/python3.6/dist-packages/django/http/request.py", line 579, in validate_host
    if pattern == '*' or is_same_domain(host, pattern):
  File "/usr/local/lib/python3.6/dist-packages/django/utils/http.py", line 291, in is_same_domain
    pattern = pattern.lower()
AttributeError: 'ellipsis' object has no attribute 'lower'
"GET /favicon.ico HTTP/1.1" 500 12107

Then I went inside the file /usr/local/lib/python3.6/dist-packages/django/utils/http.py line 291 in is_same_domain

please see the implementation of is_same_domain  I am not able find where the error is

def is_same_domain(host, pattern):
    """
    Return ``True`` if the host is either an exact match or a match
    to the wildcard pattern.

    Any pattern beginning with a period matches a domain and all of its
    subdomains. (e.g. ``.example.com`` matches ``example.com`` and
    ``foo.example.com``). Anything else is an exact string match.
    """
    if not pattern:
        return False

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


I am not able to find where the error is   Please help in resolving this

With Many Thanks,
Bharath AK
Avatar of coder

ASKER

Hi Phill

I had checked the settings.py in the project directory it doesnot have ... text inside it.

With Many Thanks,

Bharath AK
Avatar of coder

ASKER

Hi Phill,

      I am able to resolve this issue.  I add print inside is_same_domain(host, pattern): before pattern.lower()  then ran the applications.
I got three logs test_site, test_site2, eclipses.   I had searched for test_site in my project folder

I got ALLOWED_HOSTS = ['test_site', 'test_site2', ...] in settings.py.  I had missed the search in vim editor I had searched for /... in vi editor in settings.py but missed some how.  Then what I did is removed ... and it started working.

Thank you so much.

With Many Thanks,

Bharath AK
Avatar of coder

ASKER

Thanks Phill
Nice - glad you were able to find it!