0

Starting up with Django. On Ubuntu 16.04, using python3.6. On a venv started a project and running the command to start webserver. Here is the output

$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
January 03, 2019 - 14:06:57
Django version 2.1.4, using settings 'tictactoe.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

when I try to access the localhost. I get a connection refused error

$ curl -v http://127.0.0.1:8000/
*   Trying 127.0.0.1...
* connect to 127.0.0.1 port 8000 failed: Connection refused
* Failed to connect to 127.0.0.1 port 8000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 127.0.0.1 port 8000: Connection     
refused

Found that the server isn't listening on port 8000 . Verified with netstat -an

Tried with different ports also with python manage.py runserver 0:8000 Didn't help.

vnktrs
  • 1
  • 3
  • Does this help https://stackoverflow.com/questions/22952676/curl-failed-to-connect-to-localhost-port-80 ? – Ojas Kale Jan 03 '19 at 14:31
  • @OjasKale I don't think it is a curl issue. The port itself is not listening in the server and I suppose python webserver is not opening the port – vnktrs Jan 03 '19 at 14:38
  • please try "python manage.py runserver 8000" – Shubham Paliwal Jan 03 '19 at 14:49
  • So I create a django project under virtualenv with django==2.1.3 and using python==3.5.2 and ran the server and used "curl -v localhost:8000". Inspired by answer https://askubuntu.com/questions/903404/curl-fails-to-connect-to-locahost – Aman Raparia Jan 03 '19 at 14:50
  • @ShubhamPaliwal Tried it. No luck. – vnktrs Jan 03 '19 at 14:54
  • Also using the "sudo netstat -plnt" verified that 127.0.0.1:8000 has STATE LISTEN – Aman Raparia Jan 03 '19 at 14:54
  • @AmanRaparia It is not curl error. Even it fails to open in browser . – vnktrs Jan 03 '19 at 14:57
  • Can please try to open the port 8000 on your machine to accept the tcp with ufw and iptables and then again try "python manage.py runserver". Think that in the ufw deny http might be set up – Aman Raparia Jan 03 '19 at 15:18
  • what I tried to re-create your error and succed with command "sudo iptables -A INPUT -p tcp --destination-port 8000 -j DROP " and this lead to the same error. I resolved it using the command "sudo iptables -I INPUT -p tcp --destination-port 8000 -j ACCEPT" – Aman Raparia Jan 03 '19 at 15:28
  • sorry it did not help – vnktrs Jan 03 '19 at 15:40
  • I did re-provision the vm with Ubuntu 18.04. Its a vanilla server and still I face the issue. – vnktrs Jan 04 '19 at 11:43

0 Answers0