In path /getAll
I want to return a list of JSONs however I get an object is not callable , why does this occur and how can I return to my JSON list?
TypeError: 'str' object is not callable
TypeError: 'list' object is not callable
These can occur when attempting to assign values to variables these names, or by mutating their values.
Code
from flask import Flask, render_template, Response
import pymongo
from bson.json_util import dumps
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/getAll', methods=['GET'])
def getAll():
try:
conn = pymongo.MongoClient()
except pymongo.errors.ConnectionFailure, e:
print "Could not connect to MongoDB: %s" % e
db = conn['local']
collection = db.teste
myList = []
for d in collection.find():
myList.append(dumps(d))
return myList
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=True)
TrackTrace
127.0.0.1 - - [27/Mar/2016 16:51:44] "GET /getAll HTTP/1.1" 500 -
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1577, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "/usr/lib/python2.7/site-packages/werkzeug/wrappers.py", line 847, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "/usr/lib/python2.7/site-packages/werkzeug/wrappers.py", line 57, in _run_wsgi_app
return _run_wsgi_app(*args)
File "/usr/lib/python2.7/site-packages/werkzeug/test.py", line 871, in run_wsgi_app
app_rv = app(environ, start_response)
TypeError: 'list' object is not callable