pythondjangongrokcoursera-api

Ngrok Falied to complete Tunnel connection


I am working on my first Django project. Trying to connect to the auto-grader for my course through ngrok.I ran python manage.py runserver. I can see the website at http://127.0.0.1/8000 and it is working. I tried the command ngrok http 80 and got a forwarding URL. When I try to see the Http://xxxxxxxngrok.io/127.0.0.1/8000 I get the following error:

"The connection to http://444e-2600-1700-5egb-70c0-c843-879c-12ad-2b03.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address localhost:80.

Make sure that a web service is running on localhost:80 and that it is a valid address.

The error encountered was: dial tcp [::1]:80: connectex: No connection could be made because the target machine actively refused it.

I typed netstat after running the runserver command. It shows 127.0.0.1/8000 with a state "listening"

How can I resolve this?"


Solution

  • If you are hosting your upstream service at http://127.0.0.1:8000, then the command you would use to start ngrok should be: ngrok http 8000. The link that is provided to you by ngrok should work as is, as in you do not have to append anything to the end of it as you describe in your issue.

    If it still doesn't work, try rewriting the host header using: ngrok http 8000 --host-header rewrite.

    Check out the ngrok docs for more info: https://ngrok.com/docs

    Edit: Forgot to mention if you want to add logic directly to your Django app for controlling the agent, check out this example: https://pyngrok.readthedocs.io/en/latest/integrations.html#django