flask-restful

Flask API not receiving requests all of a sudden

我的梦境 提交于 2019-12-12 10:54:48
问题 I am trying to create a REST API in Flask. The thing is it runs perfectly for a few days and then all of a sudden it STOPS receiving requests altogether. Forget about not responding to requests; it just doesn't receive any requests at the first place. This is my script: from flask import Flask, jsonify from flask_restful import Resource, Api from flask_restful import reqparse from sqlalchemy import create_engine from flask.ext.httpauth import HTTPBasicAuth from flask.ext.cors import CORS conn

Flask RESTful API and authenticating for a specific user

久未见 提交于 2019-12-12 05:48:44
问题 I am relatively new to RESTful API, so it is certainly possible I am not designing this correctly. I want to return a different subsets of a JSON user object from /api/users/[user_id] based on who is authenticating. So if the user "alice" is trying to access /api/users/alice, she would get much more of her info (such as private settings, etc) than user "bob" who would simply get her public profile. I am currently using flask_restful with httpbasicauth. Right now I have the following: class

Storing user images on AWS

。_饼干妹妹 提交于 2019-12-12 05:29:30
问题 I'm implementing a simple app using ionic2, which calls an API built using Flask. When setting up the profile, I give the option to the users to upload their own images. I thought of storing them in an S3 bucket and serving them through CloudFront. After some research I can only find information about: Uploading images from the local storage using python. Uploading images from a HTML file selector using javascript. I can't find anything about how to deal with blobs/files when you have a front

Using Python Flask-restful with mod-wsgi

南楼画角 提交于 2019-12-12 03:29:32
问题 I am trying to use mod-wsgi with Apache 2.2 I have the following directory structure: scheduling-algos -lib -common -config -config.json resources -Optimization.py optimization.wsgi optimization_app.py My optimization_app.py is the following: from flask import Flask from flask_restful import Api from resources.Optimization import OptimizationAlgo def optimizeInstances(): optimization_app = Flask(__name__) api = Api(optimization_app) api.add_resource(OptimizationAlgo, '/instances') if __name__

flask-RESTful : why do I get an AssertionError when parsing an argument with the wrong type?

不打扰是莪最后的温柔 提交于 2019-12-12 03:28:10
问题 I'm using flask-RESTful for the first time. In the docs it says : Using the reqparse module also gives you sane error messages for free. If an argument fails to pass validation, Flask-RESTful will respond with a 400 Bad Request and a response highlighting the error. However in my case, I get an exception AssertionError instead. Here's the code: #! /usr/bin/python # -*- coding: UTF-8 -*- from flask import Flask from flask.ext.restful import Api, Resource, reqparse class Test(Resource):

Custom parameter validation with JSON response for Flask-RESTful

浪尽此生 提交于 2019-12-11 15:05:00
问题 I am using Flask-RESTful for creating API endpoints, and I specify the URL this way: api.add_resource(ListVersionsByStaff, '/shots/versions/<int:project_id>/<int:staff_id>') api.add_resource(ListSeasons, '/seasons/<int:project_id>') While Flask-RESTful will return an error response if the given argument is not int , it will return a HTML response. How can I return a custom JSON error response, for example: except InvalidParameter as err: abort(err.status_code, **err.to_dict()) Checking for

How to iterate over api routes in a different file than the app initialization file

本小妞迷上赌 提交于 2019-12-11 13:19:54
问题 I have an apiroutes.py file which has many the routes defined like: @api.route('/api/read', methods = ['GET']) @api.route('/api/write', methods = ['POST']) where api is an import "from . import api" I have registered my application in init .py using app = Flask(__name__) from .api_1 import api as api_blueprint app.register_blueprint(api_blueprint) where .api_1 is folder name where I have apiroutes.py file located.I want to insert a new API which gives me information of all the apiroutes in a

How to run a flask app on a remote server from a local system?

耗尽温柔 提交于 2019-12-11 11:48:59
问题 I'm able to run the flask app on the local system using app.run() . But when I try to run it on remote server using app.run(host='0.0.0.0',port='81') or app.run(host='<remote ip>') ,both don't work. I want to know if something else has to be done. 回答1: The problem is not from Flask, The IP specified in app.run(host='0.0.0.0') must be owned by your server. If you want to launch Flask on remote server, deploy the code on that server using SSH and run it using a remote session. 来源: https:/

Flask restful API urls

♀尐吖头ヾ 提交于 2019-12-11 11:46:17
问题 I am using Flask-RESTful(http://flask-restful.readthedocs.org/en/latest/index.html) in my project. Afrer reading some examples I understood that I will have only get, post, update etc methods in my Resource class. How can I make my own Resource class method with a unique url like it was in Flask with @app.route() decorator? Thanks. 回答1: Look at quick start (A Minimal API, Resourceful Routing and etc.): api.add_resource(HelloWorld, '/') api.add_resource(TodoSimple, '/<string:todo_id>') 回答2: I

Flask / Werkzeug - sockets stuck in CLOSE_WAIT

你说的曾经没有我的故事 提交于 2019-12-11 09:49:08
问题 I've run into a situation where an API built on Flask-Restul intermittently becomes non-responsive. Currently it's running from Werkzeug (which I'm aware is for non-production use only) and single threaded. To complicate things a little further this is also all wrapped up inside axscript within another application. When non-responsive, a significant number of sockets show in the CLOSE_WAIT so there's something not being handled correctly during a client initiated socket teardown. As this is