I'm trying out compute engine and I've successfully setup a vm, created a flask app as an API that accepts POST requests so I can further send emails to clients,
I keep getting a connection refused error whenever I try to make an http post request to the instace IP, I've tried using external and internal IPs, setting up a new firewall rule to allow all ports IN VPC network rules and still nothing. what could be the problem?
this is the address shown to me by my flask app,
and this is my client side code for the request.
also i want to note that the code works perfectly on my local machine.
As for Flask 2.2, the development server always shows this warning, it is not possible to disable it. The development server is not intended for use in production. It is not designed to be particularly efficient, stable, or secure. Use a production WSGI server instead. See the deployment docs from Flask for more information.
That warning applies to the development server, not Flask itself. The Flask framework is appropriate for any type of application and deployment.
You can also try running below commands to do flask run
$ export FLASK_APP=hello.py
$ export FLASK_ENV=development
$ flask run
Alternatively you can do the following
$ export FLASK_APP=hello.py
$ python -m flask run
Refer to this SO link for more information.
Related
I’ve recently tested and deployed a flask app as the minusthemiddleman website. All of the functions tested and worked in the sandbox by multiple testing methods before deployment to nginx and uwsgi in production. For some reason page 2 of the search function causes a resource problem in app as deployed. I’ve had a chance to monitor the redis directly using $redis-cli monitor and check my pip list to make everything is installed in production correctly.
The specific error is:
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
Does anybody have ideas as to why this is malfunctioning? Thanks,
I want to use GCP cloud run as a technology to run my python flask app, so I have to dockerize it. Most of examples I've seen are either using built in flask server or gunicorn server as an ENTRYPOINT, which gives a warning on a console, that it shouldn't be used on production.
My question is: does it matter with a platform like GCP cloud run which server do I use to run that code? What would be the performance impact of that choice?
You want gunicorn, and you'll need to configure it correctly.
Typically in these setups there will be an external HTTP server proxying requests to your server. So it matters rather less which webserver you're using on the backend, because it's not directly exposed.
That being said, the built-in Flask webserver isn't ideal, so gunicorn would probably be better. You will need to tweak Gunicorn's settings slightly to work correctly in container: logging, heartbeat setting, and parallelism.
See https://pythonspeed.com/articles/gunicorn-in-docker/ for details.
I work on a python3.6 app that uses flask and oauth2client.
I want to serve https instead of http in gcloud environment.
I tried using talisman-flask:
https://github.com/GoogleCloudPlatform/flask-talisman
However, when I ran their sample app locally I got this error in my browser:
This site can’t provide a secure connection
127.0.0.1 sent an invalid response.
It works fine for http, but can't apparently serve https.
Are there some Talisman configurations I need to change?
Or maybe a whole different solution altogheter?
EDIT:
I changed from debug=True to debug=False and now I get automatically redirected to https but the above error message is still there.
One rather generic approach which can work even with the standard environment local development server (which doesn't support HTTPS) would be to use a reverse proxy.
Such solutions are documented in Appengine - Local dev server with https
It's an old thread, but if you want to serve HTTPS (with or without Talisman) you need, at least, a valid certificate. Please, create one at Let's Encrypt and install in your web server, even if your site are in the web or in your local environment. If you want a good tutorial to help further, I recommend this from Miguel Grinberg, a big "Flask Guru" ;-) .
I am new to Python development. I am building a test Python app and already deployed into a web server and accessing it through public IP. Now I have updated the source(that is added some more models and templates), Now I want my public IP under port 80 should show updated code.
How do I do this?
if you have used any sort of version control, it's just commit and push/pull to the server.
if not, you have to copy the code, paste it in the server, restart the application and it work's with new code.
best approach is make a service, deploy the code with git version control, run the service and you are good to go. service will start automatically in case of system-restart and such.
I created a Django Python application in localhost and setup virtualenv for running python application. I run this application from terminal and can access with this url- http://127.0.0.1:8000/ . On hosting time (server) how can i access this application using url?
I suggest you to check out this page of the django documentation if you haven't already: https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
Deployment of a web application is not as easy as running the python development server, that is extremely simpler and is discouraged to be used on a server by the django documentation itself.
On a theoretic point of view, the reason why you can't access remotely the development server is because it binds the server on local only access: to make it accessible from an external computer you need to bind it to listen on 0.0.0.0 instead of 127.0.0.1, then you will be able to reach it on example.com:8000 depending on what the server's domain is and what port you choose. To use 0.0.0.0 you call manage.py runserver like this:
./manage.py runserver 0.0.0.0:8000
but avoid to do it, and opt for a more robust deployment :)
If your trying to deploy your application for the first time, and you want to get a feel of accessing your app from url, try heroku, https://www.heroku.com/
Easy and you don't have to worry about setting up everything.