'WinError 10013' running Django on Windows - python

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
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.
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.
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.
Cause: Winsock has malfunctioned. Attempted Solution: Tried and successfully reset winsock, but this did not solve it either.

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.

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

How to fix the connection error in django

I have created a new project in django. when I run python manage.py runserver, I am getting the msg in command prompt like below.
/var/www/samplepro/myapp$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
March 26, 2015 - 10:52:31
Django version 1.7.7, using settings 'myapp.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
when I test in browser, I am getting the page can't be displayed error. Can anyone help me to do get the django page.
You stated that you are running the server on Ubuntu while you are trying to connect it from another PC running Windows. In that case, you should replace the 127.0.0.1 with the actual IP address of Ubuntu server (the one you use for PuTTY).
I am also developing in a virtual machine.
Use ifconfig to figure out the IP address that has been assigned to your virtual machine.
Then start the server with:
python manage.py runserver <IP>:8000
Of course you could also use a different port instead of 8000. Then use that address and port in your host browser to access your server.
Note: At least in my VM, the virtual machine gets a new address from time to time, so check that in case you have trouble starting your server with the same command.
If this does not help, check your hosts file as mentioned in one of the comments.

How do I access my django app running on Amazon ec2?

So, I have looked around stack overflow + other sites, but havent been able to solve this problem: hence posting this question!
I have recently started learning django... and am now trying to run it on ec2.
I have an ec2 instance of this format: ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com on which I have a django app running. I changed the security group of this instance to allow http port 80 connections.
I did try to run it the django app the following ways: python manage.py runserver 0.0.0.0:8000 and python manage.py runserver ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com:8000 and that doesnt seem to be helping either!
To make sure that there is nothing faulty from django's side, I opened another terminal window and ssh'ed into the instance and did a curl GET request to localhost:8000/admin which went through successfully.
Where am I going wrong? Will appreciate any help!
You are running the app on port 8000, when that port isn't open on the instance (you only opened port 80).
So either close port 80 and open port 8000 from the security group, or run your app on port 80.
Running any application on a port that is less than 1024 requires root privileges; so if you try to do python manage.py runserver 0.0.0.0:80 as a normal user, you'll get an error.
Instead of doing sudo python manage.py runserver 0.0.0.0:80, you have a few options:
Run a pre-configured AMI image for django (like this one from bitnami).
Configure a front end server to listen on port 80, and then proxy requests to your django application. The common stack here is nginx + gunicorn + supervisor, and this blog post explains how to set that up (along with a virtual environment which is always a good habit to get into).
Make sure to include your IPv4 Public IP address in the ALLOWED_HOSTS section in Django project/app/settings.py script...

Can't get Django to server its dev server on my LAN

I really try not to ask questions on here, but I've been googling for a bit now and can't find the answer or another method to try. I have a CentOS box at my house hooked to a router. I've assigned it a static IP of 192.168.1.140. Because I'm lazy, I just ssh into it. When I'm goofing around with Django (learning Django/Python at the moment) and I run python manage.py runserver with a variety of IP address, I can't get my browser to access that box. I've tried
python manage.py runserver 0.0.0.0:8000
python manage.py runserver 8000
python manage.py runserver localhost:8000
python manage.py runserver 192.168.1.140:8000
python manage.py runserver 192.168.1.255:8000
python manage.py runserver 192.168.1.0:8000
python manage.py runserver 192.168.1.1:8000 #this errors out and says I can't use this IP address although this is the IP I use to access the router
When I run netstat -tln in another terminal I can indeed verify that it's listening on port 8000 to the specified address. In iptables I've run it just how it is and I've run it through tcp --dport 8000 and --sport 8000 with the same results. Just can't quite seem to crack the code. I've also setup port forwarding on my router so port 8000 is directed at 140. Is there a log somewhere I can check that I can't find on google? What am I missing?
Whilst googling I came close to an answer but I think it must be something else.
I'm running Python 2.7.5 and Django 1.5.2 through virtualenv if you need to know. Is virtualenv my issue? Thanks y'all
According to this documentation,
the right approach would be to set the python manage.py runserver xxx.xxx.xxx.xxx:yyyy to the IP address of the port you're using [Wi-Fi or Ethernet].
If the other devices are connected to the same LAN, then they should be able to access your Python VirtualEnv straight from their browsers.
Worked just fine on mine.
Also, I use DHCP - don't know if it changes anything. Just thought I'd mention that.

python manage.py runserver not work

I am trying to learn django on my mac by following along with Writing your first Django app
I run
django-admin.py startproject mysite
and it creates the files it should. Then I try to start the server by running
python manage.py runserver 8080
It's OK,the message is :
Validating models...
0 errors found Django version 1.4.2, using settings 'mysite.settings'
Development server is running at http:// 127.0.0.1:8080/ Quit the
server with CONTROL-C.
But I when I visit the 127.0.0.1:8080, I get a 504 error page:
This Page Cannot Be Displayed
The system cannot communicate with the external server ( 127.0.0.1 ).
The Internet server may be busy, may be permanently down, or may be
unreachable because of network problems. ......
What am I missing here?
Considering you are using a proxy (as mentioned in the comments). The reason for this error:
This Page Cannot Be Displayed
The system cannot communicate with the external server ( 127.0.0.1 ). The Internet server may be busy, may be permanently down, or may be unreachable because of network problems. ......
is that 127.0.0.1 is looked up at the proxy and on the proxy server there is nothing listening on port 8080
Use 'python manage.py runserver 8000' instead of 'python manage.py runserver 8080'
Worked for me.

manage.py runserver

I am running python manage.py runserver from a machine A
when I am trying to check in machine B. The url I typed is http://A:8000/ .
I am getting an error like The system returned: (111) Connection refused
You can run it for machines in your network by
./manage.py runserver 0.0.0.0:8000
And than you will be able to reach you server from any machine in your network.
Just type on other machine in browser http://192.168.0.1:8000 where 192.168.0.1 is IP of you server... and it ready to go....
or in you case:
On machine A in command line ./manage.py runserver 0.0.0.0:8000
Than try in machine B in browser type http://A:8000
Make a sip of beer.
Source from django docs
You need to tell manage.py the local ip address and the port to bind to. Something like python manage.py runserver 192.168.23.12:8000. Then use that same ip and port from the other machine. You can read more about it here in the documentation.
I was struggling with the same problem and found one solution. I guess it can help you. when you run python manage.py runserver, it will take 127.0.0.1 as default ip address and 8000. 127.0.0.0 is the same as localhost which can be accessed locally. to access it from cross origin you need to run it on your system ip or 0.0.0.0. 0.0.0.0 can be accessed from any origin in the network.
for port number, you need to set inbound and outbound policy of your system if you want to use your own port number not the default one.
To do this you need to run server with command python manage.py runserver 0.0.0.0:<your port> as mentioned above
or, set a default ip and port in your python environment. For this see my answer on
django change default runserver port
Enjoy coding .....
Just in case any Windows users are having trouble, I thought I'd add my own experience. When running python manage.py runserver 0.0.0.0:8000, I could view urls using localhost:8000, but not my ip address 192.168.1.3:8000.
I ended up disabling ipv6 on my wireless adapter, and running ipconfig /renew. After this everything worked as expected.
in flask using flask.ext.script, you can do it like this:
python manage.py runserver -h 127.0.0.1 -p 8000
For people who are using CentOS7, In order to allow access to port 8000, you need to modify firewall rules in a new SSH connection:
sudo firewall-cmd --zone=public --permanent --add-port=8000/tcp
sudo firewall-cmd --reload
I had the same problem and here was my way to solve it:
First, You must know your IP address.
On my Windows PC, in the cmd windows i run ipconfig and select my IP V4 address. In my case 192.168.0.13
Second as mention above: runserver 192.168.0.13:8000
It worked for me.
The error i did to get the message was the use of the gateway address not my PC address.
First, change your directory:
cd your_project name
Then run:
python manage.py runserver
Ok just came across this post this is a little off topic but hopefully explains a few things, The IP 127.0.0.1 points to your network card so any traffic that you cause to go to that IP address will not leave your computer.
For example modern network cards in laptops for example will not even give you that IP if you are not connected to a wifi or cabled network so you'll need to be connected at least to activate the card.
If you need to run multiple servers on the same machine but want to access them with a domain then you have a couple of options
edit your computers host file to define the domain and what IP it goes to
use a DNS Alias I set up using a cname record years ago *.local.irishado.com will point to 127.0.0.1
so for example these three domains will point to your local machine
http://site1.local.irishado.com
http://site2.local.irishado.com
http://site3.local.irishado.com
will all point to your local machine then in python projects you will need to edit the projects setting file ALLOWED_HOSTS property to hold the domain it will accept
ALLOWED_HOSTS = ['site1.local.irishado.com']

Categories