'WinError 10013' running Django on Windows

Viewed 18820

It has been almost a month since I got this problem, and I really appreciate your help. While trying to login in my Django Web App, i encounter OSError at /accounts/login/.I am able to login in 127.0.0.1:8000/admin, but not in the /accounts/login which produces the Error Code:

OSError at /accounts/login/
[WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

Request Method: POST
Request URL:    http://127.0.0.1:8000/accounts/login/
Django Version: 1.11.1
Exception Type: OSError
Exception Value:    
[WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
Exception Location: C:\Python35-32\lib\socket.py in create_connection, line 702
Python Executable:  C:\Python35-32\myvenv_python3\Scripts\python.exe
Python Version: 3.5.2
Python Path:    
['C:\\Users\\Kaleab\\Desktop\\ecomstore',
 'C:\\Python35-32\\lib\\site-packages\\sqlalchemy-1.1.7-py3.5-win32.egg',
 'C:\\Python27',
 'C:\\Python35-32\\myvenv_python3\\Lib\\site-packages',
 'C:\\Python35-32',
 'C:\\Users\\Kaleab\\Desktop\\ecomstore',
 'C:\\Python35-32\\myvenv_python3\\Scripts\\python35.zip',
 'C:\\Python35-32\\DLLs',
 'C:\\Python35-32\\lib',
 'C:\\Python35-32\\myvenv_python3\\Scripts',
 'C:\\Python35-32\\lib\\site-packages',
 'C:\\Python35-32\\lib\\site-packages\\win32',
 'C:\\Python35-32\\lib\\site-packages\\win32\\lib',
 'C:\\Python35-32\\lib\\site-packages\\Pythonwin']
 

Possible Causes and Solutions

  1. Cause: Socket access needs administrative privilege. Attempted Solution: • Granted Administrator access to python.exe by navigating to the virtual environment. • Navigate to CMD.exe , right click , properties, grant administrator privilege.

  2. Cause: Port can be already used by another program. Attempted Solution: Checked the ports using TCPView windows program and see that the port 8000 is not used by another program.

  3. Cause: Socket access blocked by Firewall and Antivirus. Attempted Solution: When I tried disabling Firewall and Antivirus, I get another error ConnectionRefusedError at accounts/login/ [WinError 10061] No connection could be made because the target machine actively refused it.

  4. Cause: Winsock has malfunctioned. Attempted Solution: Tried and successfully reset winsock, but this did not solve it either.

8 Answers

Changing the port worked for me, I was trying to run the django server. Its not a firewall issue just type port in front of your command

python manage.py runserver 7000

Since changing the port worked for @Kaleab, the problem may have been another process using that port.

I just found a Firefox process with a loopback connection from port 5000 to port 5000 (strange?). Once I closed Firefox, I was able to start my Flask server without that error.

To find out which process is using the port, see here.

run the command with port number 8080 as follows

python manage.py runserver 8080

Just restart your computer and run
python manage.py runserver
or
python manage.py runserver PORT_NUMBER
or
python manage.py runserver 8000
or
python manage.py runserver 8080

It is possible that you have another process running that is using the port. Finding and killing the process will enable you to use the 8000 port.

I got the Error Message due to my Antivirus App (Kaspersky). All i had to do was to assign manage.py in Kasperky < manage programms to trustworthy. I have a foreign version so trustworthy is a literal translation, maybe in the english version it is named different.

I solved this using a different port:

python manage.py runserver 9999

9999 Worked for me

Related