running a simple server using python's SimpleHTTPServer - python

I am trying to create a local server by following the instructions here
I ran the command and got this:
➜ ~ python -m SimpleHTTPServer 8000
Serving HTTP on 0.0.0.0 port 8000 ...
However I don't know how to access the files in the directory that I started the server in. How can I do this? Thanks

you can type localhost:8000 or 127.0.0.1:8000 in your browser.. the important bit being an address, localhost followed by the port 8000 in this case.

Related

127.0.0.1 refused to connect

On command prompt I typed
python -m HTTPServer
and I got
Serving HTTP on 0.0.0.0 port 8000
But when I try to access the localhost page it just won't open.
I also tried
http://127.0.0.1:8000/
but still, nothing opens up.
output:
Also, my pc have anaconda installed and I think that it may be hindering with 8000 port. I don't want to uninstall anaconda. How can I use this port or another new port as I m trying to learn D3?
Using python3, run the following command in the directory of your web assets:
python -m http.server 8000
This should be equivalent to using SimpleHTTPServer in python2.

Python 3 and http.server usage

I was wondering if I have index.html and in windows CMD run python -m http.server 80 while in the directory with index.html will it start a server on my IP(given I have port 80 open) and then people can just connect to my IP and see what is in index.html?
If
your router is portforwarded for TCP 80
the server is listening on 0.0.0.0
No firewalls are in the way
Then it will be publically accessible. To make it only available on local host you should host on 127.0.0.1
httpd = ServerClass(("127.0.0.1", 80), HandlerClass)
Edit: the other answer posted this good link, didn't see until after posting: Is it possible to run python SimpleHTTPServer on localhost only?
People should be able to connect to your public IP without problem. It would be a little more complex if you want to give access only from localhost:
Is it possible to run python SimpleHTTPServer on localhost only?

python -m SimpleHTTPServer - Listening on 0.0.0.0:8000 but “Page Not Found”

When I use this code
python -m SimpleHTTPServer
it is showing
Serving HTTP on 0.0.0.0 port 8000 ...
But page is not displaying.
When I used the port 80
python -m SimpleHTTPServer 80
it is working.
How to enable the port 8000
Anyone can help me with solution to this.
When I am using my own IP its working but in ssh connection port 8000 is not working only port 80 is working
http://0.0.0.0:8000
Should do the work.
The default port when browsing HTTP from a Web-Browser is 80. If you want to browser from a different port you have to specify it after the site address with leading colon.
You have to specify the port in your browser (80 is the default port)
Try http:\0.0.0.0:8000\ instead of http:\0.0.0.0\
I used to change my cloud server settings
I gave permission to access ports 7000-9000
Now it is working

Access Django devserver from another machine same network

I'm using django's builtin server to develop a site and I want other computers in the same network I'm on to be able to access the server using the local IP address.
I have seen many posts about this and after trying all suggestions it's still not allowing other computers in my network to access the site.
I run the server using
python manage.py runserver 0.0.0.0:8000
and have already opened port 8000 as you can see in the following image.
I'm running Django 1.4.2, Python 2.7.3, Fedora 18 on kernel 3.8.11-200
Any help is highly appreciated. Thanks.
Use python manage.py runserver <ip>:<port>
For example,my IP is 192.168.0.100 and I want to run django app on port 80,I have to do
[sudo] python manage.py runserver 192.168.0.100:80
My port 80 needed root permissions,maybe because I have other applications accessing it.
You also have to add the IP address to ALLOWED_HOSTS list in settings.py
By doing this all clients in the 192.168.0 network will be able to access the site at 192.168.0.100
You're starting Django as needed - it will accept connections from anywhere as soon as the connections get to it.
Check your firewall and make sure it's allowing 8000 port connections. Something like this should work:
iptables -I INPUT -p tcp -m tcp --dport 8000 -j ACCEPT
Optionally you will need to extend the INTERNAL_IPS variable in the setting to allow remote debugging: https://docs.djangoproject.com/en/dev/ref/settings/#internal-ips .
skarap is correct. If your network is configured correctly and your django application with pytho9n manage.py runserver 0.0.0.0:8000 and you still can't access your django app from the VM host there is almost certainly a firewall issue. The illustration above is good if you are running iptables.
I deployed CentOS 7 on a virtualbox VM from a Windows 7 host. I didn't know that this distribution uses firewalld, not iptables to control access.
if
ps -ae | grep firewall
returns something like
602 ? 00:00:00 firewalld
your system is running firewalld, not iptables. They do not run together.
To correct you VM so you can access your django site from the host use the commands:
firewall-cmd --zone=public --add-port=8000/tcp --permanent
firewall-cmd --reload
Many thanks to pablo v on the http://www.scriptscoop.net site for pointing this out.
You have to add the server IP to the ALLOWED_HOSTS in the settings.py
set firewall rules with
$ sudo ufw enable
$ sudo ufw allow 8000
type ipconfig
copy addr under inet
do python3 manage.py runserver your_inet_addr:8000

python -m SimpleHTTPServer - Listening on 0.0.0.0:8000 but http://0.0.0.0:8000/test.html gives "Page Not Found"

After cding to my folder I enter
python -m SimpleHTTPServer
and get
Serving HTTP on 0.0.0.0 port 8000 ...
in reply. But when I hit http://0.0.0.0:8000/test.html I get a page not found error.
I've also tried
pushd /path/you/want/to/serve; python -m SimpleHTTPServer; popd
taken from this question
When I hit ls I can see the file and the directory. Anyone know what I'm doing wrong?
I think the other two answers are trying to make it clear that 0.0.0.0 is not the URL you should be visiting. When a Python web server (like cherrypy for instance) says it is serving on 0.0.0.0 it means it is listening for all TCP traffic that ends up at that machine no matter the hostname or IP that was requested. But, if you change it such that the socket listens on 127.0.0.1 or 'localhost', then unless the request was specifically to that IP/hostname, it won't respond to the request. For example, many times you can use your machine name instead of localhost (ubuntu allows this for example). If your machine name is 'brian' and you have a server listening on 0.0.0.0:8080, you should be able to reach that server with http://brian:8080. But if that server is listening on 'localhost', even though 'brian' is set to point to 'localhost', the server won't receive the message.
You also need to be sure the file really is in the directory you are running the command from. Otherwise, the 404 response is actually correct :)
Good luck!
Have you tried http://127.0.0.1:8000/ ?
:)
You must type in the ip-address of the computer your connecting to for example 192.168.0.2:8000 Change that to the ip-address of your server.
Try browsing to http://localhost:8000/test.html or http://127.0.0.1:8000/test.html (those two should be exactly the same thing as long as your hosts file isn't all crazy-like).
0.0.0.0 is usually used by Windows as the "Not connected" IP, and can also be used as a sort of wildcard for when dealing with IPs. I am a bit confused at why your HTTP server is trying to host on 0.0.0.0, though. You may need to edit some config files and set that to 'localhost' or '127.0.0.1'.
Try to host over localhost may it help you instead of trying it on http://0.0.0.0/ like this way: python -m http.server 8000 --bind 127.0.0.1
create a directory e.g. mkdir HTTPServer_dir
move inside the folder cd HTTPServer_dir
typing the command (according to python version) python -m SimpleHTTPSever 8000
(or the port you want)
go on a browser and type http://127.0.0.1:8000/
Done !!!
You could make a simple index.html page inside the HTTPServer_dir so you can see an html page instead of directory listing
Run ifconfig on Linux or ipconfig on Windows to find the ip address of the server.
$ sudo ifconfig
wlan0 Link encap:Ethernet HWaddr 30:3a:64:b3:be:6a
inet addr:192.168.1.103 Bcast:192.168.1.255 Mask:255.255.255.0
Here in case the url would be:
http://192.168.1.103:8000/test.html
try this in python3
python -m http.server 8000 --bind 127.0.0.1
and in your browser this url:
http://127.0.0.1:8000/
Sometimes the same port number is used by some other service. So we can try with some other port like
python -m SimpleHTTPServer 9090
And then simply hit http://{your system IP}:9090/
this works for me.
this worked for me,replacing your machine name with
http://localhost:x000
This worked for me on Windows 8. Did not download any software!
In cmd:
Go to the directory that your file is in.
python -m SimpleHTTPServer
Shows "Serving HTTP on 0.0.0.0 port 8000 ..."
Now, find out your system name. For Windows 8: Control Panel -> System. You will see the computer name here. Let's say it is "Abhinav".
Your local server will be hosted at "Abhinav.local:8000".

Categories

Resources