0

I am new to flask Restful api i am trying to make a rest api which get JSON data.While entering the curl command i get the 404 error.Here is the code can anyone please help.

#flask/bin/python
from flask import Flask, jsonify, abort, request, make_response,url_for,render_template
from flask.ext.restful import Api, Resource
#from flask.ext.restful import restful, Api
app = Flask(__name__, static_folder ="\Flae\app\default")
api= Api(app)

@app.errorhandler(404)
def page_not_found(e):
return 'Sorry, Nothing at this URL.', 404


class Task(Resource):

    tasks = [
        {
            'id': 1,
            'message': u'You are notified'
        },
        {
            'id': 2,
            'message': u'You are notified'
        }
    ]

    def get_tasks():
        return jsonify( { 'tasks': tasks } )

api.add_resource(Task, '/api/v1/tasks')

if __name__ == '__main__':
    app.run()

The error displayed is:

  C:\Users\Chaitanya>curl http://127.0.0.1:5000/
  Sorry, Nothing at this URL.
  C:\Users\Chaitanya>curl http://127.0.0.1:5000/api/v1/tasks
  {"status": 500, "message": "Internal Server Error"}
  C:\Users\Chaitanya>

Log Generated is:

   C:\Users\Chaitanya\Desktop\Flae\batch-fuogy-01\default>python main.py
   * Running on http://127.0.0.1:5000/
   * Restarting with reloader
   127.0.0.1 - - [10/Feb/2015 17:39:09] "GET /api/v1/tasks HTTP/1.1" 500 -
   Traceback (most recent call last):
   File "D:\Python27\lib\site-packages\flask\app.py", line 1836, in __call__
   return self.wsgi_app(environ, start_response)
   File "D:\Python27\lib\site-packages\flask\app.py", line 1820, in wsgi_app
   response = self.make_response(self.handle_exception(e))
   File "D:\Python27\lib\site-packages\flask_restful\__init__.py", line 263,in error_router
   return original_handler(e)
   File "D:\Python27\lib\site-packages\flask\app.py", line 1403, in handle_exception
   reraise(exc_type, exc_value, tb)
   File "D:\Python27\lib\site-packages\flask_restful\__init__.py", line 260,in error_router
   return self.handle_error(e)
   File "D:\Python27\lib\site-packages\flask\app.py", line 1817, in wsgi_app
   response = self.full_dispatch_request()
   File "D:\Python27\lib\site-packages\flask\app.py", line 1477, in full_dispatch_request
   rv = self.handle_user_exception(e)
   File "D:\Python27\lib\site-packages\flask_restful\__init__.py", line 263, in error_router
   return original_handler(e)
   File "D:\Python27\lib\site-packages\flask\app.py", line 1381, in handle_user_exception
   reraise(exc_type, exc_value, tb)
   File "D:\Python27\lib\site-packages\flask_restful\__init__.py", line 260,  in error_router
return self.handle_error(e)
  File "D:\Python27\lib\site-packages\flask\app.py", line 1475, in  full_dispatch_request
  rv = self.dispatch_request()
  File "D:\Python27\lib\site-packages\flask\app.py", line 1461, in dispatch_request
  return self.view_functions[rule.endpoint](**req.view_args)
  File "D:\Python27\lib\site-packages\flask_restful\__init__.py", line 431, in wrapper
  resp = resource(*args, **kwargs)
  File "D:\Python27\lib\site-packages\flask\views.py", line 84, in view
  return self.dispatch_request(*args, **kwargs)
  File "D:\Python27\lib\site-packages\flask_restful\__init__.py", line 516, in dispatch_request
  assert meth is not None, 'Unimplemented method %r' % request.method
  AssertionError: Unimplemented method 'GET'
5
  • Please, show flask's log or console output. Commented Feb 10, 2015 at 11:54
  • '* Running on 127.0.0.1:5000 127.0.0.1 - - [10/Feb/2015 17:12:25] "GET / HTTP/1.1" 404 - 127.0.0.1 - - [10/Feb/2015 17:12:45] "GET /api/v1/tasks HTTP/1.1" 500 - 127.0.0.1 - - [10/Feb/2015 17:21:43] "GET /api/v1/tasks HTTP/1.1" 500 -' Commented Feb 10, 2015 at 12:03
  • please, turn on debug mode: app = Flask(name, debug=True) and print log again. Commented Feb 10, 2015 at 12:04
  • And make curl 127.0.0.1:5000/api/v1/tasks Commented Feb 10, 2015 at 12:09
  • Well i have tried the curl command as shown in question i have also edited the question and displayed the log. Commented Feb 10, 2015 at 12:21

1 Answer 1

4

You should rename 'get_tasks' method to 'get' as it required by flask-restful docs

Sign up to request clarification or add additional context in comments.

2 Comments

that wasn't completely obvious from the docs, actually. thanks for spelling it out!
Definitely there is not a chance to figure this out from the docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.