lundi 24 avril 2017

Python Flask Web API [Heroku]: It runs locally but shows Application Error when deployed

I have done a search on StackOverflow looking for an answer that will help me to get my Web API working, but somehow, I still don't have the answer that I need. I have followed all the necessarily steps up till the moment I can deploy the project to heroku (through Github), and it shows no build error. Procfile is already included, so is my requirements.txt. Please see below:

Project Directory:

app-directory/
  |-main-api.py
  |-Procfile
  |-requirements.txt
  |-..other files..

Procfile:

web: gunicorn app:main-api

requirements.txt:

  • Flask
  • PyMongo
  • Gunicorn

In main-api.py...

@app.route('/', methods=['GET'])
def get_index():
    customers = mongo.db.customers

    output = []

    for c in customers.find():
        output.append({'_id': c['_id'], 'first_name': c['first_name'],
                   'last_name': c['last_name'],
                   'date_of_birth': c['date_of_birth'],
                   'is_online': c['is_online']})

    return jsonify({'results': output})

And finally...running the web project in Heroku itself:

Heroku Web - Python-Flask-Error

Anyone with similar experience or have the right solution to this problem, appreciate if you can share it. Thanks a million folks!




Aucun commentaire:

Enregistrer un commentaire