Flask host='0.0.0.0' Google Chrome could not connect - flask

I just begun using Flask and tried to run the hello_world example (hello.py)
The point is that I run the server through ssh on a remote machine and I want to browse it from my local machine so I used
app.run(host='0.0.0.0'),
However when I browse on chrome I put let's say http: //RemoteMachineIP:5000/ I got:
Oops! Google Chrome could not connect to RemoteMachineIP:5000
The remote machine has multiple ethernet IP addresses so I tried them (as http: //RemoteMachineIP:5000/) and I am always getting the same error.
I have also tried using app.run(host='LocalMachineIP') in hello.py but I got this error Flask [Errno 99] Cannot assign requested address.
Am I missing something ?

If you can run the server but the browser won't see it, it is a firewall problem.
If you can't assign the ip port, probably there is a PID already using the port, so you should try
lsof -i :5000
Then
kill -9 [PID From the lsof]

Related

Running code server on gcp cloud shell gives error when previewing

I'm trying to run code-server on gcp cloud shell. I downloaded the following version
https://github.com/cdr/code-server/releases/download/v3.9.2/code-server-3.9.2-linux-amd64.tar.gz, which I think is the correct one, extracted the contents and ran
code-server --auth none
This gave the following output
[2021-04-06T00:53:21.728Z] info code-server 3.9.2 109d2ce3247869eaeab67aa7e5423503ec9eb859
[2021-04-06T00:53:21.730Z] info Using user-data-dir ~/.local/share/code-server
[2021-04-06T00:53:21.751Z] info Using config file ~/.config/code-server/config.yaml
[2021-04-06T00:53:21.751Z] info HTTP server listening on http://127.0.0.1:8080
[2021-04-06T00:53:21.751Z] info - Authentication is disabled
[2021-04-06T00:53:21.751Z] info - Not serving HTTPS
Now when I try Web Preview -> preview on port 8080 nothing happens I just get a blank screen and on the code console I see the following error
2021-04-06T00:50:04.470Z] error vscode Handshake timed out {"token":"e9b80ff7-10f9-4089-8497-b98688129452"}
I'm not sure what I need to do here ?
In cloud shell editor, create a file with .sh extension, and install the code-server by using these steps:
export VERSION=`curl -s https://api.github.com/repos/cdr/code-server/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")'`
wget https://github.com/cdr/code-server/releases/download/v3.10.2/code-server-3.10.2-linux-amd64.tar.gz
tar -xvzf code-server-3.10.2-linux-amd64.tar.gz
cd code-server-3.10.2-linux-amd64
To run the vscode.sh file using terminal:
./vscode.sh
If a warning “permission denied” comes, type chmod +x vscode.sh and then again proceed with
running the file.
To navigate to the folder:
cd code-server-3.10.2-linux-amd64/
To navigate to the bin:
cd bin/
To start the server :
./code-server --auth none --port 8080
Now you can see the VSCode IDE in your browser either by using web preview->preview on port 8080 option or the HTTP server link in your terminal.
My gut is saying that one must study this article (Expose code-server) in great detail. I think you will find that Code server is listening on IP address 127.0.0.1 at port 8080. Your thinking then is to access this server using Web Preview on port 8080 .... however ... pay attention to the IP addresses of your virtual machine. The IP address 127.0.0.1 is known as the loopback address. It is ONLY accessible to applications running on the SAME machine. My belief is that when you run Web Preview, you are trying to access the IP address of your Cloud Shell machine which is NOT 127.0.0.1.
If you read the above article, the story goes on to show how to use SSH forwarding to provide a front-end to whatever this application may be.

Trying to run Flask on localhost, refused to connect

I'm trying to run my Flask application on 127.0.0.1:4141 but all I've been getting is this which essentially is the localhost refused to connect, ERR_CONNECTION_REFUSED & vice versa.
link
I was running my application on PuTTY. If I run it on Flask on my local cmd prompt, it works for some reason.
I'm just wondering whether there's anything I can do to get it working.
Are you trying to reach the url from the same machine? if not try to change the ip from 127.0.0.1 to 0.0.0.0

Cannot access to port 80 on Google Cloud VM instance

I have setup Django in Linux Ubunut on GCE and run using :
sudo -E home/us1/python/bin/python /home/us1/project/manage.py runserver 0.0.0.0:80
Server is started but when using my browser on ip_adress:80, I got an error message that :
This site can’t be reached, Too long to respond.
1) I checked the firewall set, open 80 is open...
Am not sure how I can get access to this website ?
Solution (in case other people) are in same:
1) Ping the IP with CMD bash to check how is Ping.
2) Use Firefox which returns the HTTP error message
(chrome doesn't in normal mode).

SSH tunnelling to a remote server with django

I'm trying to set up an SSH tunnel to access my server (currently an ubuntu 16.04 VM on Azure) to set up safe access to my django applications running on it.
I was able to imitate the production environment with Apache WSGI and it works pretty good but since I'm trying to develop the application I don't want to make it available to broader public right now - but to make it visible only for a bunch of people.
To the point: when I set up the ssh tunnel using putty on Windows 10 (8000 to localhost:8000) and I run http://localhost:8000/ I get the folowing error:
"Not Found HTTP Error 404. The requested resource is not found.".
How can I make it work? I run the server using manage.py runserver 0:8000.
I found somewhere that the error may be due to the fact that the application does not have access to ssh files, but I don't know whether that's the point here (or how to change it).
Regards,
Dominik
After hours of trying I was able to solve the problem.
First of all, I made sure putty connects to the server and creates the desired tunnel. To do that I right-clicked on the putty window (title bar) and clicked event log. I checked the log and found the following error:
Local port 8000 forwarding to localhost:8000 failed: Network error:
Permission denied
I was able to solve it by choosing other local port (9000 instead of 8000 in my instance).
Second of all, I edited the sshd_config file: sudo vi etc/ssh/sshd_config
and added these three lines:
AllowAgentForwarding yes
AllowTcpForwarding yes
GatewayPorts yes
I saved the file and restarted the ssh service:
sudo service ssh stop
sudo service ssh start
Now when I visit localhost:9000 everything works just fine.

how could i connect to Ambari from hortonworks through url "sandbox.hortonworks.com:8080"?

i got installed Hortonworks data platform (HDP 2.4) on oracle virtual box, when i trying to use storm streaming analytics it uses to connect ambari by url
sandbox.hortonworks.com:8080
instead of
127.0.0.1:8080
loop back address and i got an error message over browser
Error : This site can’t be reached
so tell me that how could i assign
sandbox.hortonworks.com:8080
domain name to loop back address from virtual machine OS terminal.
Just add this line
127.0.0.1 localhost sandbox.hortonworks.com
to-
If you're on a windows machine, this file
%systemroot%\system32\drivers\etc\hosts
If you're on a Mac, then, this file
/etc/hosts
This will need to be done for your host machine(the one on which you installed VirtualBox) and not inside the VM.
If you are using bridged mode or host-only-adapter, replace the 127.0.0.1 with your VM's IP, so it should look like
192.168.56.101 localhost sandbox.hortonworks.com
That should help you use the FQDN.