0
我是新來的燒瓶Restful api我想讓休息api得到JSON data.While輸入curl命令我得到404錯誤。這裏是代碼任何人都可以請幫助。在python的燒瓶休息api中的錯誤404
#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()
顯示的錯誤是:
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>
日誌中生成是:
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'
請顯示燒瓶的日誌或控制檯輸出。 – 2015-02-10 11:54:29
'*運行於http://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 - ' – 2015-02-10 12:03:34
請打開調試模式:app = Flask(__ name__,debug = True)並重新打印日誌。 – 2015-02-10 12:04:53