Questions tagged [flask-restful]

Flask-RESTful provides an extension to Flask for building REST APIs. Flask-RESTful was initially developed as an internal project at Twilio, built to power their public and internal APIs.

Project repo is maintain on Github currently.
The latest document is here
Its pypi info can be find here

1619 questions
16
votes
2 answers

TypeError: Object of type function is not JSON serializable when using flask_jwt_extended int RESTful API

I'm building a REST API using flask. I'm using postman for testing a route that creates a new item in my database, but only if the user is logged in. The routes for registering and login are working well, the last one returns the token using…
16
votes
2 answers

POST csv/Text file using cURL

How can I send POST request with a csv or a text file to the server running on a localhost using cURL. I have tried curl -X POST -d @file.csv http://localhost:5000/upload but I get { "message": "The browser (or proxy) sent a request that…
Krishnang K Dalal
  • 2,322
  • 9
  • 34
  • 55
16
votes
2 answers

what does endpoint mean in flask-restful

I defined some resource called WorkerAPI using flask-restful and the plan is to process POST request from /api/workers/new and GET request from /api/workers/. When using the following code api.add_resource(WorkerAPI,…
nos
  • 19,875
  • 27
  • 98
  • 134
16
votes
3 answers

Is there a pythonic way to skip decoration on a subclass' method?

I have an class which decorates some methods using a decorator from another library. Specifically, the class subclasses flask-restful resources, decorates the http methods with httpauth.HTTPBasicAuth().login_required(), and does some sensible…
Jotham Apaloo
  • 648
  • 7
  • 10
15
votes
1 answer

Display image stored as binary blob in template

I have a model with an image stored as a binary blob. I want to display this image, along with other data about the object, in a template. Since the image is not a separate file, I can't figure out how to display it. I've tried setting headers,…
Tim
  • 2,000
  • 4
  • 27
  • 45
14
votes
1 answer

Flask restful pagination

I need to throw together an very simple API with a short deadline. Flask-restful seems ideal except for one thing: I can't find anything in the documentation about pagination. Given a simple endpoint like this: from flask import Flask, request from…
Neil
  • 3,020
  • 4
  • 25
  • 48
13
votes
1 answer

Error while building a RESTApi using flask_restful

Flask RESTApi newbie here I am trying to build a RESTapi service in Flask (and I am trying to save the output as a .txt file) using flask_restful for a code of mine using the pydifact module as follows: import datetime from pydifact.message import…
reinhardt
  • 1,873
  • 3
  • 9
  • 23
13
votes
1 answer

Flask app context for sqlalchemy

I am working on a small rest api in flask. Api has route that registers a request and spawn separate thread to run in background. Here is the code: def dostuff(scriptname): new_thread = threading.Thread(target=executescript,args=(scriptname,)) …
Abgo80
  • 233
  • 1
  • 3
  • 9
13
votes
1 answer

Flask CORS - no Access-control-allow-origin header present on a redirect()

I am implementing OAuth Twitter User-sign in (Flask API and Angular) I keep getting the following error when I click the sign in with twitter button and a pop up window opens: XMLHttpRequest cannot load…
Daniel Gaeta
  • 774
  • 2
  • 9
  • 22
13
votes
1 answer

Raising A Custom Error with Flask-Restful

All, I'm trying to raise a custom error using Flask-Restful, following the docs. For testing purposes, I've defined and registered the errors dictionary exactly link in the docs: api = flask_restful.Api(app, errors=errors). However, when I want to…
GG_Python
  • 3,436
  • 5
  • 34
  • 46
13
votes
3 answers

Flask-RESTful custom routes other than GET,PUT,POST,DELETE

In Flask-RESTful we add an api route like the below api.add_resource(CuteKitty,'/api/kitty') class CuteKitty(Resource): def get(self): return {} def post(self): return {} def put(self): return {} def delete(self): return None,…
cackharot
  • 688
  • 1
  • 6
  • 13
12
votes
4 answers

Flask-restful - Custom error handling

I want to define custom error handling for a Flask-restful API. The suggested approach in the documentation here is to do the following: errors = { 'UserAlreadyExistsError': { 'message': "A user with that username already exists.", …
JahMyst
  • 1,616
  • 3
  • 20
  • 39
12
votes
1 answer

'NoneType' object is not subscriptable

I am creating an ios app that uses a server written in flask + python, and when I make a connection to the server to register a user I keep getting a 'NoneType' object is not subscriptable error in my server.py file. Basically my question is what is…
Lucas Padden
  • 305
  • 1
  • 4
  • 12
12
votes
7 answers

Got Failed to decode JSON object when calling a POST request in flask python

I have written a simple REST-ful web server in python with flask following steps in this tutorial; but I've got a problem calling POST request. The code is: @app.route('/todo/api/v1.0/tasks', methods=['POST']) def create_task(): if not…
Zeinab Abbasimazar
  • 9,835
  • 23
  • 82
  • 131
12
votes
1 answer

Flask MethodView vs Flask-Restful Resource

What is difference between MethodView and Resource? It implements API by flask-restful: class API(Resource): decorators = [...,] def get(self): # do something def post(self): # do something def put(self): #…
Tony
  • 1,019
  • 2
  • 13
  • 25