Hello everyone, I fairly new to python (especially with Flask).
I have made a flask restful api which works perfectly fine on my local machine but the mongoDB part using mlab gives "Internal Server Error 500" when I try to run from pythonanywhere.
I have used pymongo to access it.
from flask import Flask from flask_restful import Resource, Api
from pymongo import MongoClient from flask_pymongo import PyMongo
import urllib from flask import jsonify
app = Flask(name) api = Api(app)
app.config['MONGO_DBNAME'] = '<DATABASE>' app.config['MONGO_URI'] = 'mongodb://<USER>:' + urllib.quote("<PASSWORD>")+ '@ds141358.mlab.com:41358/<DATABASE>'
mongo = PyMongo(app) @app.route('/star', methods=['GET']) def get_all_stars():
valuesCollection = mongo.db.restaurants output = [] for s in valuesCollection.find(): output.append({'name' : s['name']}) return jsonify({'result' : output})
if name == 'main': app.run()
I am using urllib as per RFC I have to escape '@' characters in my username and password in connection
Please help me out!
Thanks,