flask-restful

Using Flask SQLAlchemy from worker threads

▼魔方 西西 提交于 2019-12-11 06:17:02
问题 I have a python app that uses Flask RESTful as well as Flask SQLAlchemy. Part of the API I'm writing has the side effect of spinning off Timer objects. When a Timer expires, it executes some database queries. I'm seeing an issue in which code that is supposed to update rows in the database (a sqlite backend) is actually not issuing any UPDATE statements. I have verified this by turning the SQLALCHEMY_ECHO flag on to log the SQL statements. Whether or not the code works seems to be random.

how to make parse of list(string) not list(char) in parse argument of list?

情到浓时终转凉″ 提交于 2019-12-11 06:01:02
问题 I use flask_restful in flask My code like: from flask_restful import Resource, reqparse apilink_parser = reqparse.RequestParser() apilink_parser.add_argument('provider_id', type=int,required=True) apilink_parser.add_argument('name', type=str, required=True) apilink_parser.add_argument('func_id', type=int) apilink_parser.add_argument('method', type=str) apilink_parser.add_argument('url', type=str) apilink_parser.add_argument('parameter',type=list) apilink_parser.add_argument("expectreturn",

Flask Testing a put request with custom headers

孤街浪徒 提交于 2019-12-11 03:14:50
问题 Im trying to test a PUT request in my Flask app, using flasks test client. Everything looks good to me but i keep getting 400 BAD request. I tried the same request using POSTMAN and I get the response back. Here is the code from flask import Flask app = Flask(__name__) data = {"filename": "/Users/resources/rovi_source_mock.csv"} headers = {'content-type': 'application/json'} api = "http://localhost:5000/ingest" with app.test_client() as client: api_response = client.put(api, data=data,

Do not allow any extra fields in Flask-restplus models

ε祈祈猫儿з 提交于 2019-12-11 00:17:33
问题 I am using Flask Rest-plus models to validate a POST payload, however the I want the model to error out if any extra/unknown fields are present. Model which am using: interface_config = api.model('Network Interface Validation', { 'gateway': fields.String(required=True, description='Gateway IP'), 'subnet': fields.String(required=True, description='Subnet IP'), 'netmask': fields.String(required=True, description='Netmask'), 'vlan_id': fields.Integer(required=True, description='VLAN ID'), 'type'

Flask - AttributeError: 'module' object has no attribute 'items'

荒凉一梦 提交于 2019-12-10 23:24:03
问题 I am using flask-restful and have the following API class: views.py from datetime import date from flask import jsonify from flask.ext.restful import Resource, reqparse from backend import db from .models import User, Post, Comment, WorkExperience from flask.ext.restful import fields, marshal from backend.helpers import AuthRequiredResource, UserMixin class CommentList(UserMixin, AuthRequiredResource): def __init__(self): self.fields = { 'id': fields.Integer, 'body': fields.String, 'added_on'

Getting CORS (Cross-Origin…) error when using python flask-restful with consuming AngularJS (using $http)

我是研究僧i 提交于 2019-12-10 19:44:58
问题 I use a python program for providing a restful service with the flask-restful extension. I want to consume it with a AngularJS app. Everything works (for the moment) on my localhost. For consuming the service I use AngularJS $http as you can see below. Everytime I do a call I get this damn CORS error (see below)... I tried many different things after searching for one and a half day but nothing helps me to prevent this problem and I really don't know what else to do.. Unfortunately there is

Gevent blocked by flask even use monkey patch

╄→гoц情女王★ 提交于 2019-12-10 18:24:12
问题 I'm using the flask+gevent to build my server, but the gevent named 'getall' was blocked by flask, so the 'getall' function cannot print message in this code. The monkey patch is in use. import time import WSGICopyBody from flask import Flask import gevent def handle_node_request() : while True : print 'in handle_node_request' gevent.sleep(1) def getall() : print 'in getall' def create_app() : app = Flask(__name__) app.wsgi_app = WSGICopyBody.WSGICopyBody(app.wsgi_app) app.add_url_rule('/node

Flask-Restful taking over exception handling from Flask during non debug mode

与世无争的帅哥 提交于 2019-12-10 14:59:23
问题 I've used Flask's exception handling during development ( @app.errorhander(MyException) ) which worked fine even for exceptions coming from Flask-Restful endpoints. However, I noticed that when switching to debug=False , Flask-Restful is taking over the exception handling entirely (as with this propagate_exceptions is False too). I like that Flask-Restful is sending internal server errors for all unhandled exceptions, but unfortunately this also happens for those that have a Flask exception

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

人走茶凉 提交于 2019-12-10 02:12:04
问题 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 the service: curl -d username:password http://localhost:5000/api/v1.0/1234567 How do I achieve the same within my unit test's get() ? Since my get/put/post require authentication otherwise the test would fail. 回答1: From RFC 1945, Hypertext Transfer

Calling flask restful API resource methods

拥有回忆 提交于 2019-12-09 05:22:00
问题 I'm creating an API with Flask that is being used for a mobile platform, but I also want the application itself to digest the API in order to render web content. I'm wondering what the best way is to access API resource methods inside of Flask? For instance if I have the following class added as a resource: class FooAPI(Resource): def __init__(self): # Do some things super(FooAPI, self).__init__() def post(self, id): #return something def get(self): #return something api = Api(app) api.add