Я пытаюсь создать простой API для возврата GET в JSON с данными из таблицы, где база данных является pg sql, однако, когда я делаю CURL, я получаю ошибку 500
flask .py
from flask import Flask, request, jsonify
from flask_restful import Resource, Api
from sqlalchemy import create_engine
from json import dumps
import psycopg2
db_connect = create_engine('postgresql+psycopg2://postgres:postgres@localhost/dbname')
app = Flask(__name__)
api = Api(app)
class ApiZabbix(Resource):
def getMemory(self):
try:
conn = db_connect.connect()
query = conn.execute("select * from \"TBLNAME\"")
result = [dict(zip(tuple(query.keys()), i)) for i in query.cursor]
return jsonify(result)
except Exception as e:
print("[ALERT] Error caused by: {}".format(e))
api.add_resource(ApiZabbix, '/apizb')
if __name__ == '__main__':
app.run()
Завиток
curl localhost:5000/apizb
Выход
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python3.7/dist-packages/flask_restful/__init__.py", line 468, in wrapper
resp = resource(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/flask/views.py", line 89, in view
return self.dispatch_request(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/flask_restful/__init__.py", line 573, in dispatch_request
assert meth is not None, 'Unimplemented method %r' % request.method
AssertionError: Unimplemented method 'GET'