I'm trying to run a simple web server on a Raspberry Pi with Flask. When I run my Flask app, it says:
running on http://127.0.0.1:5000/
But when I enter this address on my laptop's in Chrome, I get
ERR_CONNECTION_REFUSED
I can open 127.0.0.1:5000 on the Raspberry Pi's browser. What do I need to do to connect from another computer?
Run your app like this:
if __name__ == '__main__':
app.run(host='0.0.0.0')
It will make the server externally visible. If the IP address of the machine is 192.168.X.X then, from the same network you can access it in 5000 port. Like, http://192.168.X.X:5000
when you are running the server via flask run change it to flask run --host=0.0.0.0
to connect, find the IPV4 address of the server that your script is running on. On the same network, go to http://[IPV4 address]:5000
A reason could also be in firewall refusing incoming connections on port 5000. Try:
sudo ufw allow 5000
app.run(host='0.0.0.0',port=5000)
if you run your app in this way then your server will be visible externally.
Steps by Setp:
Run your app by using the following command
app.run(host='0.0.0.0',port=5000)
Go to the window cmd . Type ipconfig and get the get the IPV4 adress suppose your IPV4 address is 192.168.X.X
Go to the mobile browser and type the 192.168.X.X:5000
If you have debug = True inside your app.run(), then it will not be visible to other machines either. Specify host and port inside app.run() without the debug = True.
You will have to run the development server such that it listens to requests on all interfaces and not just the local one
Ask Flask to listen on 0.0.0.0:PORT_NUMBER
or any other port you may choose
On MacOS 12.4 (Monterey) I couldn't load localhost nor my local IP but it worked with both of these:
0.0.0.0
127.0.0.1
Just change the URL in the browser if it loads with "localhost".
Both devices must be connected to same network.
Use app.run(host='0.0.0.0',port=5000) and run with your own Ipv4
address like his http://[Your Ipv4 address]:5000
If you are connecting this with android app then don't forget to
put INTERNET permission in manifest file.
Contrary to popular believe 127.0.0.1 is not the same a localhost.
I solved the issue above by setting 127.0.0.1 explicitly on both ends.
Well i was also here to know answer but i guess i found out problem. The reason is that you may not activated or run flask that's why it is showing error. For that you have to start from terminal "flask run" and then surely your flask will run...
The issue may occur, if VPN is on, so try to switch it off.
Related
I'm on windows, but on my Virtualbox I have one debian server.
I have create a Dart example and run it with:
dart run --pause-isolates-on-start --observe
With this i can connect to:
http://127.0.0.1:8181/XDFGgXmZ5Xc=/devtools/#/?uri=ws%3A%2F%2F127.0.0.1%3A8181%2FXDFGgXmZ5Xc%3D%2Fws
But this link don't work!
When I try to access even inside the Virtualbox with the W3M (command line browser) there is no output.
I have checked for open ports and the port 8181 is open.
Can you guys tell me some ideas to fix this?
You need to change the bind-address since the default are localhost which means only programs running inside your VM can get access to the observatory.
From dart help run:
--enable-vm-service=<[<port>[/<bind-address>]]> Enables the VM service and listens on the specified port for
connections (default port number is 8181, default bind address is
localhost).
If you want to make the observatory to every single network interface on your machine, you can change the bind-address to 0.0.0.0 instead. Be sure you don't allow this to be externally accessed from the internet. Alternative, you can specify the IP of the network interface you want the observatory to listen on.
dart run --pause-isolates-on-start --observe --enable-vm-service=8181/0.0.0.0
I have a local ruby on rails server set up on -
http://localhost:3000/
I have added allow arbitrary loads in the info.plist
When I run the app on the simulator it works fine, but when I try to run it on the iPhone it doesn't. The app just crashes.
Looking at similar questions I found that I need to use the actual IP. I also turned the Internet sharing on from the preferences.
So I found out my local IP address which is - 192.168.0.8
So in Safari I am testing it out like this http://192.168.0.8:3000/
But it doesn't work!
How can I get this up and running?
Start your rails server like this:
rails server -b 0.0.0.0
Note that if you have a firewall on your computer you may need to open your firewall or run on another port, like port 80.
rails server -b 0.0.0.0 -p 80
It'd be easier if you Ngrok.
Just start your server, as usually and by default with port 3000, and then run ngrok as to start listening on such port:
./ngrok http 3000
This will give you a public IP which will be accessible for your devices.
I've tried from all Stack Overflow's existing answer for this topic but they're not working for me. I've tried using http proxy with Squidman, created local network between my iPhone and my mac with static IP, then accessing it using my machine IP address. I've also tried ping my mac using my Windows pc, it can't ping to my mac but my Mac can ping my Windows, both firewall are disabled.
Any configuration that I missed?
if your desktop is (192.168.0.101), you need to run your service as 0.0.0.0:8080 (example port). Usually ports are bound to 127.0.0.1
This way your router can direct requests from 192.168.0.101:8080 to your application. Ensure you undo this in case you exposing sensitive data.
Assuming your mac ip is $ip, you can do the following to make port $port accessible from your local network:
$ ssh -R $ip:$port:localhost:$port localhost
It will relay all requests from $ip:$port to the localhost server.
Example:
$ ssh -R 172.16.0.111:3000:localhost:3000 localhost
(Posted on behalf of the OP)
The main problem that causes my Mac can't be accessed by other device is the firewall blocked ICMP. Then I disabled it using this command below:
pfctl -d
My firewall rules list:
Hello i am trying to access my Webrick rails server that i started on my ubuntu to my windows 7 pc locally. I checked on ifconfig in my virtual box and used the inet:10.0.2.15 when i run my rails server and also used port 80 like this:
rails server -b 10.0.2.15 -p 80
It didn't gave me an error in the terminal but when i try to go to 10.0.2.15 on my windows browser, it says it can't connect. I tried disabling the firewall in windows but still wont work. Thank you.
Choose another network type for your VM ubuntu. I suggest the Bridged Network. Reboot vm, it should obtain ip in same network as your windows host (example 192.168.0.XXX). Then you will be able reach your rails server from network At any port 80 or 3000.
Can you share your ubuntu with the vm, via the apache server too? is that started? In macs you have to enable web sharing (or something similar to that wording). ON ubuntu what happens when you do localhost:80... if i recall it should say it works! or something like that.
I have a Rails site that I'm developing on localhost Ubuntu and I have a mobile.
My site is running on http://localhost:3000.
I want to access this directly via my mobile browser not going through the internet.
Is there any way to access it via WiFi or some other way?
If your computer is accessible from internet, just enter in your mobile browser:
http://your.ip:3000/
You could also create a local network (via wifi for instance), connect to it with your cell phone and then do the same thing.
If you are using Rails 4.2+, start the server using:
rails server -b 0.0.0.0
(see http://edgeguides.rubyonrails.org/4_2_release_notes.html#default-host-for-rails-server).
1.) get your local ip by typing:
ifconfig |grep inet
into your shell/terminal. your ip usually looks like this: 192.xxx.xxx.xx
2.) then start the rails server with:
rails server -b 0.0.0.0
3.) your application can now be reached by typing:
192.xxx.xxx.xx:3000 into the browser.
Using ngrok
So basically, you run the command
./ngrok http 3000
And you will see the output like that
And all you need is copy the highlight URL and paste to the browser.
Execute
rails s -b IP_ADDRESS
Access mobile: IP_ADDRESS:3000
First find your Ip and note it down by typing ifconfig terminal(you should be connected to wifi or network)
ifconfig
than run the rails server by typing
rails server -b 0.0.0.0 (YOUR IP )
and press Enter
SERVER WILL BE RUNNING ON YOUR_IP:3000
2. Now connect your mobile with the same network and open url
https://YOUR_IP:3000
CONGRATS YOU ARE RUNNING LOCALHOST ON MOBILE
On rails-server machine:
Make sure you're running rails-server.
Get your IP address, I got "192.168.1.112" for example.
On mobile:
Access through browser by using:
http://<your_ip_address>:3000
http://192.168.1.112:3000
NOTE: Your mobiles need to have the same network with rails-server machine.
To get yourself IP address, run this command in your rails-server machine.
MacOS or Linux Terminal:
ipconfig getifaddr en0 || ipconfig getifaddr en1
# => 192.168.1.112
Description:
ipconfig getifaddr en0 is for wifi connections
ipconfig getifaddr en1 is for wired connections
Windows:
ipconfig
Then looking for IPv4 Address.
Running rails-server
On rails-server machine, it's okay to regularly run:
bin/rails s
If you found issue, you can try the following:
bin/rails s -b 0.0.0.0
Note: 0.0.0.0 is not an IP address, it's a shortcut for the system binding call to use all available IP addresses including 127.0.0.1, localhost.
Access through http://localhost:3000/
if you get ipconfig command not found on ubuntu
Try:
ip route to get the IP address then you can run rails server as explained in other answers.
rails s -p 3000 -b 192.168.0.102 (Replace IP with your system's IP).
Now you should be able to access on you mobile browser by just entering
http://192.168.0.102:3000/
run your server on 0.0.0.0:port_no rather then 127.0.0.1 or localhost
then check your IP address by typing a command in your terminal
ipconfig
here you can check your host machine's IP address.
-Now we have to enable 3000 in your case port to be accessible in the network
write following commands
sudo ufw enable
sudo ufw enable port_no
sudo ufw status
then you will be able to see your port is enabled
-Now you can access your server in any device browser using IP address:port_no
Check out this picture where I am accessing Django Web App running locally on Ubuntu and I am able to access it on my windows laptop which is in the same network via ip_addess:port_no which in my case is 8000
You can access the same website at