This is a curious situation:
Python folder
Let us say the path is ~/pyfolder/
I run the command python -m SimpleHTTPServer 8080 inside the folder. Now on localhost:8080, I get index.html which is inside the pyfolder.
I stop the server by killing the process, check that nothing is going on the port 8080.
Node folder
Let us say the path is ~/webfolder/
I run PORT=8080 node server.js inside the folder. I expect to see ~/webfolder/index.html(i have setup express js route for / to show this file) on port 8080. But what is see is ~/pyfolder/index.html. This is weird.
Furthermore, when a call is made to 8080, node console show a request being made on the port which is handled by express but still the page shown is from the python folder.
Can someone explain what is the problem here?
EDIT:
Also, the happens only on browser without incognito mode. As soon as I try this in incognito mode, everything runs fine.
Related
I am trying to run the python .py file in PyScript. To do that, I need to load python file in a server because PyScript cannot access local file:
<py-script src="./greet.py"></py-script>
So I tried to create local server by entering this command in the terminal in the folder of my project:
python -m http.server
It has been over 30 minutes now and the server is not on. It shows that the terminal local is still running. It should take no more than a minute to be done. I have tried to locate specific port with:
python -m http.server 80 but it still doesn't work.
What should I do?
You might try also binding the server to a specific link-local IP address, using something like python -m http.server --bind 127.0.0.1 8000. The page should then appear at 127.0.0.1:8000.
This was necessary for me on Windows - even after allowing Python permissions to access the network. Not sure if it's Windows-related, or Python not identifying the correct NIC to bind to, or what.
This is my first question so please bear with me. I looked for answers to my question, but found none unique to my issue.
I recently tried my hand at hosting an onion site with Python3 and the Tor browser. I created a directory called "tor_service" and placed a simple index.html file inside.
I then ran python3 -m http.server --bind 127.0.0.1 8080 in the same folder. Next, I opened another terminal session and started the Tor client. I navigated to, and appropriately modified the torrc file under the "hidden services" section, using port 8080. I opened my browser and went to localhost:8080 to verify everything was working. To my surprise, I saw the simple web page I wrote. So far, so good.
I then navigated to the Tor folder that contained the hostname to get the unique oinion address, and using cat hostname, obtained the string of characters followed by .onion.
I pasted the onion address in the Tor browser and again, I saw the simple html page I wrote.
Here's the problem: when I shut down my computer for the night, resumed the next day, and started the Python server and Tor client, instead of displaying my web page, I got a page that read "Directory of /" that displayed all of the folders on my hard drive. This is obviously a serious security issue. Not only were the folders on my hard drive on display for the web to see, they were all hyperlinks.
I don't understand what I did wrong. I didn't modify or move any files or change any settings, and I started the Python http.server and Tor client as usual.
I closed the terminal windows opened new ones, but got the same results. A third time resulted in the same outcome. I understand that using the Python "server" isn't the optimal method to host a site, but if I can't get something so simple to work, I fear I won't be able to actually write (much less diagnose problems on) a more robust server that operates using more than a single line of code.
I'm using the Linux subsystem on Windows 10 and the latest iteration of Ubuntu (20.4, I think).
Any pointers are greatly appreciated. I can craft and style a nice looking webpage, but I'd like to get proficient at the back-end side of things.
Are you sure you have navigated back to the project folder in your terminal?
If you're running the
python3 -m http.server --bind 127.0.0.1 8080
command immediately after opening the terminal, it will run in the 'default' folder rather than your project folder (you'll need to 'move' back into the project folder using cd).
How come I can't do anything else on terminal when It's running a localhost. Like I run a google app engine on it and make a new local host, I for example try to see what directory I'm in or even change directories, it doesn't respond to any of my requests? Thank you
That instance of the terminal will be busy doing the thing you asked it to. But you can just open a new window or tab.
I am trying to run a Python app in Google App Engine. The UI doesn't work so I tried using the command lines. I tried restarting my PC, I tried changing port with "dev_appserver.py --port=9999 ." but it still says Unable to bind localhost:8000:
raise BindError('Unable to bind %s:%s' % self.bind_addr)
google.appengine.tools.devappserver2.wsgi_server.BindError: Unable to bind localhost:8000
The app server starts two servers; one for your application, the other for the development console. It is that second server that is causing the problem here; it normally would be run on port 8000.
Change the ip address for the development console with the --admin_port switch:
dev_appserver.py --admin_port=9000
You may still want to change the port for the main application server too, of course.
Also see the command-line arguments documentation for dev_appserver.py.
It is possible some application is binding to your port in autostart event.
It's highly probable to be the same service you are trying to run. In that case try killing the process
ps -ef | grep 'process_name'
Use kill -9 'pid' to end the process.
A computer restart did it, closing google app engine launcher, restarting the computer then launching again did the trick...
terminate old terminal and start in new, its the easiest way I
could find
Being unable a port is usually a sign of one of two things:
You don't have permissions
Something is already running there.
You can try hitting the local port 8080 with your browser to see what is there, and kill it if it shouldn't be.
As for permissions - only look for this afterwards. Presuming you are in windows (you didn't specify this), then you should be able to bind this as a normal user.
As for the command line - have you tried replacing the "=" with a space - I've seen both forms in documentation for app-engine.
dev_appserver.py --port 9999 .
I can't seem to figure this out. I created a new Ubuntu VM on Azure and I can SSH into it. I installed Node (which I've done many times) and I tried to run the test app from nodejs.org:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
However, when I go to the IP (which is the same one I SSHed into the box from) + :1337 it just never loads. I tried :80 too, but still no luck. I also tried running python -m SimpleHTTPServer on :8000 and I still can't view the site. I must be missing something.
Just so you know, I'm just trying to setup a simple dev box with a bunch of projects on it. I want to be able to work on my projects anywhere. Some are 100% front-end JS projects so SimpleHTTPServer would be fine. Some are Node projects too. In either case, I just want to be able to hit some port and see what I'm working on.
Oh also I opened up the Azure firewall to the VM, redirecting traffic from port 80 to port 1337 (https://www.evernote.com/shard/s5/sh/3aef8e76-04f6-48cb-84f9-32462bc425a7/f0cd749773a9d09cee66d00fe3e707c0)
You are listening loopback ip address. Try .listen(1337, '0.0.0.0'); to listen on all network interfaces
urgh azure. i cannot get port 80 open. is it the machine iptables?? some azure magical thing.
i know it cant be that hard.
unlike your view i do not see 'NONE' for load balancer. i see '--'/ whatever that means.