7

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.

matebende
  • 389
  • 4
  • 15
Kaleab Woldemariam
  • 1,849
  • 3
  • 14
  • 32
  • https://stackoverflow.com/questions/2778840/socket-error-errno-10013-an-attempt-was-made-to-access-a-socket-in-a-way-forb – gliptak Jul 19 '17 at 14:16
  • @gliptak I saw that post, unfortunately did not solve my problem. I am not sure if it is a User Account Control (UAC) issue in Windows 8.1. Although I can run as Administrator, I am still denied socket permission. I have looked into cheking FIrewall and Antivirus , but to no avail. – Kaleab Woldemariam Jul 20 '17 at 11:14

8 Answers8

11

I will take running the server with different port as the answer, although I am not able to see port 8000 is used in stackoverflow suggested commands. Use: python manage.py runserver 8080.

Kaleab Woldemariam
  • 1,849
  • 3
  • 14
  • 32
  • Worked for me. However, it is quite strange to know that the port 8000 was not being used anywhere else. Regardless, this trick worked for me. – Abbas Nov 12 '18 at 06:22
  • This worked for me as well, but don't know why it worked – manpikin Feb 19 '19 at 08:44
  • It worked for me but I would like to know why a port might be used somewhere else all on a sudden.TIA – Sihat Afnan Jul 18 '20 at 18:54
3

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

Amit nayal
  • 31
  • 1
0

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.

Neal Gokli
  • 425
  • 5
  • 18
  • 1
    When I run netstat -a -b in my cmd, one of the lines was [svchost.exe] TCP [::]:8000 TIA-NEXCHMB1:0 LISTENING. I think my application was trying to use a port that was already being used, because I was attempting to run a django application on 8000. So I changed my port to 8080 and it woked – manpikin Feb 19 '19 at 08:50
0

run the command with port number 8080 as follows

python manage.py runserver 8080

Sadhana Singh
  • 121
  • 3
  • 10
0

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

Vikash P
  • 41
  • 2
0

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.

David Louda
  • 328
  • 2
  • 10
0

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.

black_hole_sun
  • 589
  • 4
  • 21
-1

I solved this using a different port:

python manage.py runserver 9999

9999 Worked for me

Rishabh Kumar
  • 1,981
  • 3
  • 7
  • 21