Cannot use runserver, but http.server works

This is the strangest thing. Whenever I use the runserver command, I get this error message:
Error: You don't have permission to access that port.

The same thing happens no matter what port I designate, whether it’s 8000 or 8001 or 8002.

Here’s the kicker:
When I run the Python http.server on those very same ports, I get no error, and the Python server runs.

My project used an older minor version of Python and Django before I upgraded, but I’m at a loss as to continue how to troubleshoot this issue.

1 Like

Interesting. Can you post the complete runserver command you’re using, along with the version of Django and the operating system you’re running this on?

The error message you’re referencing comes from django/runserver.py at 54e94640ace261b14cf8cdb1fae3dc6f068a5f87 · django/django · GitHub
(Or the corresponding line of code depending upon the version you’re using.)

That try block calls get_handler and run - either of which could throw this error.

If I had to diagnose something like this, I’d be tempted to do one (or both) of:

  • Edit the runserver command to print the complete error and traceback to see if there’s more information.
  • Try the runserver_plus command from django-extensions (which is a “must have” in my projects anyway.)

I’ll continue to troubleshoot based on your advice. This is the command I’m running by default:

manage runserver

Using Windows 10, Django 3.2, and Python 3.9.4.

I was able to use runserver_plus, and I was able to run the server just fine. However, I received this output:

Error occurred during checks: PermissionError(13, 'Permission denied')

 * Restarting with windowsapi reloader
Performing system checks...

System check identified no issues (0 silenced).
Error occurred during checks: PermissionError(13, 'Permission denied')


Django version 3.2, using settings 'myproject.settings.dev'
Development server is running at http://[127.0.0.1]:8000/
Using the Werkzeug debugger (http://werkzeug.pocoo.org/)
Quit the server with CTRL-BREAK.
 * Debugger is active!
 * Debugger PIN: ***
 * Running on http://127.0.0.1:8000/ (Press CTRL+C to quit)

I ran manage check, and the system didn’t find any other errors.

The error seems to be related to file permissions. I did reset all the file permissions, but continue to receive the same error. I just read that Python could be confusing a folder as a file in Windows, and that would cause the problem. I’m now trying to figure out what folder that could be in my project.

I’m continuing to troubleshoot.

I added a print statement to check_errors function in the runserver_plus command to show the files that have exceptions. It seems like a handy tool to add to the output anyway. Regardless, I discovered that the check_errors function is checking a file that simply doesn’t exist within the virtual environment. Now, it turns out, that I’m using a git repository, and the path to that file does exist on a different computer (path to the activate_this.py script), but not the one I’m developing on currently. I just tried re-creating the virtual environment, but I’m getting the same issue. I’m interested in other ideas. There is no reference to this file anywhere in the project.

I found the issue, and it is quite embarrassing. Apparently, many years ago on this particular project, I edited the wsgi.py file. I think I had edited it to take advantage of waitress. I had since returned to using Apache, but I never changed the wsgi file after that. Truth be told, I use neither waitress nor Apache during development; I think I was just doing a test with it. Honestly, I don’t remember why I modified that file, but I had hard-coded the path to the virtual environment on the modular level without any exception handling.

Upon commenting it, everything worked fine. I would have never been able to do this without your help, though. Thank you so much!