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
12
votes
1 answer

errorhandler not firing when DEBUG is False

I'm using errorhandlers to catch and handle certain kinds of exceptions: @app.errorhandler(CustomException) def handle_custom_exception(error): return redirect('redirect-path', code=301) This works correctly when DEBUG is True, which implicitly…
ganduG
  • 615
  • 6
  • 18
12
votes
1 answer

How to customize response content type in flask-restful?

I want to be able to return something other than application/json i.e. kml. I have the following: @api.representation('application/vnd.google-earth.kml+xml') def kml(data): return Response(data,…
Rolando
  • 58,640
  • 98
  • 266
  • 407
12
votes
6 answers

Flask-Restful POST fails due CSRF protection of Flask-WTF

I am using normal flask web + flask-restful. So I need CSRF protection for web but not for REST. The moment I enable CsrfProtect(app) of flask-wtf, all my post unit tests for flask-restful return a 400. Is there a way to disable CSRF protection for…
Houman
  • 64,245
  • 87
  • 278
  • 460
11
votes
3 answers

EXCEPTION: Response with status: 0 for URL: null in angular2

I'm getting following exception, when I'm trying to connect to remote API using anguar2 http. Also my web server is receiving request and responding properly. I'm able to make a successful curl request to the local server. EXCEPTION: Response with…
Asif
  • 479
  • 2
  • 6
  • 12
10
votes
1 answer

Is it possible to use Flask RestX wih Flask's 2.0+ async await?

Usage of async/await was presented in Flask 2.0. (https://flask.palletsprojects.com/en/2.0.x/async-await/) I am using Flask-RestX so is it possible to use async/await in RestX requests handlers? Something like: @api.route('/try-async') class…
10
votes
1 answer

Simple request parsing without reqparse.RequestParser()

flask_restful.reqparse has been deprecated (https://flask-restful.readthedocs.io/en/latest/reqparse.html): The whole request parser part of Flask-RESTful is slated for removal and will be replaced by documentation on how to integrate with other…
mic
  • 1,190
  • 1
  • 17
  • 29
10
votes
1 answer

Upload CSV file using Python Flask and process it

I have the following code to upload an CSV file using Python FLASK. from flask_restful import Resource import pandas as pd ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) class UploadCSV(Resource): def post(self): files =…
Dinesh
  • 1,135
  • 2
  • 15
  • 22
10
votes
3 answers

How to disable csrf for a view with flask-wft for a restapi?

I get problem for disable csrf using flask-wtf for a restapi. The problem is similar like here: Flask-Restful POST fails due CSRF protection of Flask-WTF, but I use flask original instead of flask-restful. I use the @csrf.exemptdecorator, and I did…
xirururu
  • 5,028
  • 9
  • 35
  • 64
10
votes
3 answers

python-requests post with unicode filenames

I've read through several related questions here on SO but didn't manage to find a working solution. I have a Flask server with this simplified code: app = Flask(__name__) api = Api(app) class SendMailAPI(Resource): def post(self): …
DeepSpace
  • 78,697
  • 11
  • 109
  • 154
10
votes
1 answer

flask-restul nested resources

Im refactoring my rest api server to use Flask-RESTful, and im having some doubt about some particular cases where i need to get a list of resources that belong to another. Some thing like this: /api/v1/users/john/orders How would you design this?…
Sebastian
  • 1,243
  • 1
  • 18
  • 34
10
votes
1 answer

Blueprint and factory pattern work together?

I am working on a restful service using flask-restful, and I want to leverage both factory pattern and blueprint in my project. in app/__init__.py I have a create_app function to create a flask app and return it to outside caller, so the caller can…
jeffrey
  • 238
  • 7
  • 15
10
votes
3 answers

How to send username:password to unittest's app.get() request?

This is part of my unit test in Flask-RESTful. self.app = application.app.test_client() rv = self.app.get('api/v1.0/{0}'.format(ios_sync_timestamp)) eq_(rv.status_code,200) Within the command line I could use curl to send the username:password to…
Houman
  • 64,245
  • 87
  • 278
  • 460
10
votes
2 answers

How to send password to REST service securely?

I am using Flask-Restful to build a REST service. The iOS device will then connect to this REST backend to sync the local data. The service will be accessed over a https connection. The REST service is stateless and the user has to authenticate upon…
Houman
  • 64,245
  • 87
  • 278
  • 460
9
votes
3 answers

Flask API to provide JSON files to a simple HTML+JS+CSS webapp while keeping it secure

I've made a simple webapp that is going to show some data in a table, which will be updated weekly. This update it done in the backend with some python code, that scrapes and alters some data, before putting it in a SQLite database. After doing…
bjornasm
  • 2,211
  • 7
  • 37
  • 62
9
votes
3 answers

Cannot return 404 error as json instead of html from a Flask-Restful app

I am working on a simple Flask REST API test and when I call the {{url}}/items for example I get the items list. However if a call is passed to an endpoint that does not exist for example {{url}}/itemsss then I get the error 404 in html. I would…
Kintaro
  • 189
  • 1
  • 1
  • 8