I have created a web application in python using the Flask framework. I have hosted this python application in IIS on windows server2012.
when I called this application with URL https://localhost/ on the server machine, I am getting a quick response(less than a second). But when I tried to call the same application from another machine inside the corporate network, it is taking more than 2mins time to get the response. I am calling the web application through the IP address of the server machine i.e XX.XXX.XX.XXX:80.
could anyone answer why is it taking too much time and how to get rid of this latency time?
I have used below resources to create the web application and opening the inbound port.
python deployment:
https://medium.com/#bilalbayasut/deploying-python-web-app-flask-in-windows-server-iis-using-fastcgi-6c1873ae0ad8
Inbound port opening:
https://manage.accuwebhosting.com/knowledgebase/2886/How-to-configure-IIS-to-access-website-using-IP-address.html
Regards,
Naresh.
My problem has been solved, i have tried with host name instead of IP address. It is so fast.
Regards,
Naresh.
Related
I'm learning AWS and I'm currently trying to deploy a Flask API over HTTPS. I set up an EC2 instance running Apache. I've already set up SSL on the site using ELB, and I tried to deploy flask over HTTPS with the following:
if __name__ == '__main__':
context = ("server.crt", "server.key")
app.run(host="0.0.0.0",port=5000,debug=True,ssl_context=context)
However, I don't think the site is even starting the Flask server properply, as even though everything loads and I receive a message that Flask is running on https://0.0.0.0:5000/, sending a simple GET request over the browser doesn't work as the request just never loads and it eventually times out. It's almost behaving as if there is no server running on port 5000.
On the other hand, when I ran this program over http instead of https, it worked perfectly fine. Can anyone help me out in terms of what I should do? Thank you.
Based on the comments.
The solution to the issue was termination HTTPS connections on the ELB. This way, the communication between ELB and EC2 instance can be conducted using HTTP which is simple and easier to manage on the instances.
I have a Flask application currently using http being hosted on an ec2 instance. I want to host my application using https. Currently with http, I am able to access my application (running on 0.0.0.0 port 80) by just accessing the ec2 public IP address (displays Running on http://0.0.0.0:80/, and I am able to use my app at http://IP).
I am following this tutorial to test https support: https://blog.miguelgrinberg.com/post/running-your-flask-application-over-https.
When I add the most basic app.run(ssl_context='adhoc') to my program, the app is now Running on https://0.0.0.0:80/, but I am unable to access my app at https://IP. I opened up my port 403 in my EC2 settings however I am still unable to communicate with my app using https...no response whenever I make a request.
The same no response occurs when I run the application with gunicorn. Am I missing something? I think my requests are well formed, however I am never able to communicate with my app when using https.
Simple way is put your instance behind ALB. ALB is not only load balancer, but also integrate ACM for free.
I'm creating a python flask api on remote desktop and running it on localhost of remote desktop.
Is there anyway I can access this api from my local machine?
We are working in a team and I want to share this with my team members, but this is confidential and not to be deployed on open server.
We want to post and get the result with every member's local machine from api runnnig on remote desktop.
Both of our local machines and remote desktop are windows10.
Sorry for being abstract but I'm searching for any way out. Thanks.
Well, you should open your way to this API. You'll have to set up a VPN or IP address filter in the server so you can access the server from your network while still have it secured on the Internet. You can also setup a simpler proxy if you prefer it. I'll not cover the details on how to setup a VPN or proxy since it can get pretty extensive, but a Google search will help you out find the best alternative for you.
AFAIK, the Remote Desktop Protocol does not allow for any kind of VPN. However, if you can switch to TeamViewer, it does have an easy to setup VPN system that will allow you to get into the network with few configuration. Once a VPN is configured, it will work like if you were in the same network as the server, so from there you can access your API from your host machine by just going to the IP address of the server.
Do notice the security policies of whoever owns the server, since you can get into trouble if you don't have permission to enable some access from the outside. Security goes always in front of comfort.
Short term solution:
Firstly download ngrok for your operating system.
For debugging and testing purposes you can expose a secure tunnel connection to your API by running this command in your command prompt / terminal.
ngrok http <PORT_NUMBER>-host-header="localhost:<PORT_NUMBER>"
Where PORT_NUMBER is the port number in which your flask application is running.
Example if your flask application is running at port 5000 then simply execute this command:
ngrok http 5000 -host-header="localhost:5000"
Running this will give you two hostnames one with HTTP and other a secure HTTPS connected by a tunnel like this for a duration of 8 hours after which the command needs to again re-run.
Which you can call remotely
Long term solution:
Deploy flask application using FastCGI
or
To a cloud infrastructure provider like Microsoft Azure which gives readymade templates for flask applications.
I've just started learning network developing using Flask. According to its official tutorial:
Externally Visible Server
If you run the server you will notice that the server is only
accessible from your own computer, not from any other in the network.
This is the default because in debugging mode a user of the
application can execute arbitrary Python code on your computer.
If you have the debugger disabled or trust the users on your network,
you can make the server publicly available simply by adding
--host=0.0.0.0 to the command line:
flask run --host=0.0.0.0
This tells your operating system to listen on all public IPs.
However, when I try to access 0.0.0.0:5000 on another device, I got an error: ERR_CONNECTION_REFUSE. In fact, I think this behavior is reasonable, since people all around world can use 0.0.0.0:5000 for different testing purposes, but isn't the tutorial implying that adding --host=0.0.0.0 can make my webpage "accessible not only from your own computer, but also from any other in the network"?
So, my question is:
What does adding --host=0.0.0.0 do?
How can I access my webpage on device B while the server is running on device A?
You don't access the Flask server on another computer by going to 0.0.0.0:5000. Instead, you need to put in the IP address of the computer that it is running on.
For example, if you are developing on a computer that has IP address 10.10.0.1, you can run the server like so:
flask run --host=0.0.0.0 --port=5000
This will start the server (on 10.10.0.1:5000) and listen for any connections from anywhere. Now your other device (say, on 10.10.0.2) can access that server by going to http://10.10.0.1:5000 in the browser.
If you don't have the host=0.0.0.0, the server on 10.10.0.1 will only listen for connections from itself (localhost). By adding that parameter, you are telling it to listen from connections external to itself.
If I run my flask app on my local machine I get proper results by connecting to http://127.0.0.1:5000/report?id=1
But now I want to make it externally visible by deploying my flask in a VM in azure. I have opened the port 80 on my VM. And I'm running the flask app using this:
if __name__ == '__main__':
app.run(host='0.0.0.0')
I'm still not able to connect to my flask server using this (assume the public IP address of my VM is x.x.x.x):
http://x.x.x.x:5000/report?id=1
Any suggestions how should I go ahead with it?
Edit: I'm able to psping my VM's public IP address on port 80.
The problem isn't related to Flask, since you opened up your application to listen on any public IP (0.0.0.0).
Moreover you should do a proper port mapping in your azure configuration. Google said, you might have a look here: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-set-up-endpoints/
EDIT
Another idea, where some colleages often run into, is that you may have skype open which somewhat uses port 80/443 and therefore is blocking it. Shutdown skype if you do so or use a different port for your webapp.
So here's the deal with Azure:
If you open a port from the Azure portal, the firewall in your VM STILL blocks that port. You have to manually go in and create a firewall setting in your VM to keep the port 5000 open for your flask server. Once that is done, you should be able to connect to it.