Garfonzo
Garfonzo

Reputation: 3966

Django test server suddenly not working?

I have been developing a webapp using the Django web framework. I set up an alias a long time ago so that when I type go-d at the command prompt (running Ubuntu Linux server) it initiates the command ./manage.py runserver 123.456.789.132:2222/ (all fake information here). This has been working fine for the last, I don't know, 6 months.

Tonight, something strange happened. I was working away (remotely with Putty) and suddenly my connection was dropped. I checked the log files on the server and it looked like someone from another country was trying to access the web server (I run an active website off this server too). Seeing as how the accesses looked suspicious, I decided to blocked them with a deny from line in the apache2 config file.

After blocking their IP addresses, I tried to fired up the Django test server with the same command. However, now I get the Error: That port is already in use. error.

When I do a netstat -antwup it does not show any port 2222 established or listening (which I interpret as port 2222 not being in use).

Could this new port in use issue be related to the out-of-town unfriendly visitors to my site?

Any help?

[EDIT - Update:] Ok, so I tried doing a manual ./manage.py runserver 123.456.789.123:2244 (using a different port) which worked. Then I went back to the original alias of go-d which uses the ORIGINAL port (2222) and it is working. I suppose I could say that my question is answered, but now I am curious as to what happened. Why was the port I usually use suddenly already in use? Does the Django test server do that sometime?

Any thoughts?

Thanks!

Upvotes: 2

Views: 1326

Answers (2)

softwareplay
softwareplay

Reputation: 1409

Just in the name of completeness, i've had the same problem too a couple of time and it was a problem of database connection, so check you're settings but in that case it was giving me an error after some time waiting fr the server to start.

Upvotes: 0

cwoebker
cwoebker

Reputation: 3288

This is a problem that happened to me quite often too. If a programm isnt closed properly the socket mgiht still be listening on the port. For example when qutting something with Ctrl+C. This stays for some time and at one point the port frees up again. Just change the port if it happens, should be the best way to do it for you.

There are ways to get around that, but youd need to play with django a little.

I read something about that once, if you want to i could look if i find it again.

A way to check on this in pure python would be.

try:
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
    s.bind((HOST, PORT))
except socket.error, e:
    if e....
        print "address already in use"

Upvotes: 4

Related Questions