I am new to GCP App engine. I am trying to make web server using flask on App engine. I tested the version of my code on localhost and it is working fine. But when I am trying to deploy it in the App Engine of GCP it is giving me this strange error "app logs".
error logs
Here is my code for the flask
app.run(threaded = True, host='127.0.0.1', port=80)
Thanks!!
You don't need to call app.run() in your main.py file -- App Engine will do that for you. Simply initialize the app variable in this file instead.
Related
I am using flask socket.io configured with eventlet on a free heroku instance. According to the flask socket.io documentation: https://flask-socketio.readthedocs.io/en/latest/ running socketio.run(app) will start a webserver if eventlet is installed.
I have a local react web app attempting to establish a WebSocket connection with this app engine instance. The web app uses socket.io and initially defaults to polling HTTP requests. These requests all timeout-- I'm unable to establish a web socket connection. I'm not sure what might be causing my issue, whether it is my app engine configuration or my flask socket.io setup.
Here is my initialization code for flask socket.io:
app = Flask(__name__)
socketio = SocketIO(app)
socketio.init_app(app, cors_allowed_origins="*")
..
..
if __name__ == '__main__':
socketio.run(app, debug=True)
Here is my Procfile:
web: python3 server.py
Here is the web app code attempting to set up the connection:
import io from 'socket.io-client'
const socketURL = "<app-engine-instance-url>:5000"
const socket = io.connect(socketURL)
You mentioned Heroku, then switched to App Engine. I assume you still meant Heroku?
The application running on Heroku must honor the $PORT environment variable and put the website on that port. Try this:
socketio.run(app, port=int(os.environ.get('PORT', '5000')))
Then from your client application connect to the Heroku URL for your app.
I have developed a Machine learning model in anaconda prompt using Python3 so to deploy it and to run it anywhere dynamically on GitHub or as a webservice what is the way?
I have already used Pickle command but it didn't work for me.
import pickle
file_name = "cancerdetection.ipynb"
It didn't deploy my model as webservice.
You can try using flask. It uses python and deploys as a web application. Here's some sample code you can try.
from flask import Flask, render_template, request
app = Flask(__name__, static_url_path='/static')
#app.route('/')
def upload_file():
return "hello world"
if __name__ == '__main__':
app.run(host="0.0.0.0")
By setting
host="0.0.0.0"
you're deploying your application on the net by using your local machine as a server.
This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Closed 4 years ago.
I'm running my flask web app on local from command line using python __init__.py command. I want to run/deploy flask web without using any command. Like spring web app.
init.py
from flask import Flask, url_for
from flask import jsonify
from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware
import db_config
app = Flask(__name__)
app.config['APPLICATION_ROOT'] = '/my-web-app'
def simple(env, resp):
resp(b'200 OK', [(b'Content-Type', b'text/plain')])
return [b'Hello my app User']
#app.route("/")
def hello():
return "Hello world"
#app.route('/test', methods=['GET'])
def get_tasks():
db = db_config.getconnection();
cur = db.cursor()
cur.execute("SELECT * FROM emp")
items = cur.fetchall()
print(items)
db.commit()
cur.close()
db.close()
return jsonify({'tasks': items})
app.wsgi_app = DispatcherMiddleware(simple, {'/my-web-app': app.wsgi_app})
if __name__ == "__main__":
app.run()
Is there any way to create .WAR file of flask web app and deploy it on server? And start web app when we give request.
Is there any way to create a Java .WAR file from a Flask app? Possibly, but I really wouldn't recommend it. Python is not Java.
Is there any way to deploy a Flask application on a server? Oh yes, lots of ways. The Deployment Options page in the Flask documentation lists several options, including:
Hosted options: Deploy Flask on Heroku, OpenShift, Webfaction, Google App Engine, AWS Elastic Beanstalk, Azure, PythonAnywhere
Self-hosted options: Run your own server using a standalone WSGI container (Gunicorn, uWSGI, Gevent, Twisted), using Apache's mod_wsgi, using FastCGI, or using old-school vanilla CGI.
Of the self-hosted options, I would definitely recommend nginx rather than Apache as a front-end web server, and nginx has built-in support for the uWSGI protocol, which you can then use to run your app using the uwsgi command.
But I would definitely recommend looking into one of the hosted options rather than being in the business of running your own web server, especially if you're just starting out. Google App Engine and AWS Elastic Beanstalk are both good platforms to start out with as a beginner in running a cloud web application.
I have an application using Flask and MongoEngine on heroku.
My configuration looks like this:
from flask import Flask
from flask.ext.mongoengine import MongoEngine
app = Flask(__name__)
#am setting proper configuration based on database uri
if os.environ.get('MONGOLAB_URI'):
app.config.from_object(herokuConfig)
else:
app.config.from_object(localConfig)
MongoEngine(app)
This was working fine up to yesterday, but this morning I am unable to run the application.
After looking into heroku debug logs, I observed AutoReconnect: not master error, but I am able to run it locally.
I have read some documentation regarding the above error occurring due to a read_preference setting.
I am unable to solve this, and am looking forward to suggestions.
I am trying to run gae app without dev_appserver.py, and have following error
AssertionError: No api proxy found for service "xmpp"
room = webrtc.Room.get_by_key_name(room_key)
I found in the app.yaml inbound_services:
- channel_presence
How to enable channel_presence directly in application.py
Unless otherwise specified, libraries included with the App Engine SDK are expected only to work within the App Engine environment. You cannot just import the XMPP library included with the App Engine SDK and expect it to work in a non-GAE application.