falconframework

Deploy Python Falcon app with Apache2

荒凉一梦 提交于 2019-12-12 03:33:24
问题 I have developed an api using falcon framework (v1.0). Now, I want to deploy this api on apache2 server with mod_wsgi at amazon EC2 instance. I'm running my app using wsgiref package on EC2 server. import falcon from wsgiref import simple_server api = app = falcon.API() class Resource(object): def on_get(self, req, resp): print("i was here :(") if 'fields' in req.params: print(req.params['fields']) print(len(req.params['fields'])) print(type(req.params['fields'])) res = Resource() api.add

Same Origin Policy violated on localhost with falcon webserver

孤街浪徒 提交于 2019-12-12 01:59:10
问题 I am running an elm frontend via elm-reactor on localhost:8000 . It is supposed to load json files from a falcon backend running via gunicorn on localhost:8010 . This fails. The frontend is able to load static dummy files served by elm-reactor ( :8000 ) but when I try to replace the dummies by the actual backend ( :8010 ) it fails due to a missing header: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8010/api/sheets. (Reason:

Redirect from falcon authenticate

二次信任 提交于 2019-12-11 14:06:19
问题 In my falcon app I want to redirect to another page from the authenticate function. I am doing this: resp.status = falcon.HTTP_301 resp.set_header('Location', '/http://foo.bar.com:8004/falcon_passthrough/') But it still calls the underlying endpoint on return and does not redirect. Is there a way to cause this redirect and not call the underlying endpoint? 回答1: If you are using 1.0.0rc1 just do: raise falcon.HTTPMovedPermanently(location) 来源: https://stackoverflow.com/questions/37300822

SqlAlchemy: Could not locate column in row for column 'translate'

淺唱寂寞╮ 提交于 2019-12-11 08:26:06
问题 I have a problem with my endpoint in Falcon framework, I have two models Class with access to DB but when execute the seconds class, this raise an exception: sqlalchemy.exc.NoSuchColumnError: "Could not locate column in row for column 'translate' I don't have a 'translate' column in my database or in my object mapping. Version: Python 3.6.2 PyMySQL==0.7.11 SQLAlchemy==1.1.11 My Code: endpoint: def on_post(self, req, resp, courseid, examid): with self.db.connect() as cnn: mdl_party = Party(cnn

Python falcon and async operations

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 12:54:05
问题 I am writing an API using python3 + falcon combination. There are lot of places in methods where I can send a reply to a client but because of some heavy code which does DB, i/o operations, etc it has to wait until the heavy part ends. For example: class APIHandler: def on_get(self, req, resp): response = "Hello" #Some heavy code resp.body(response) I could send "Hello" at the first line of code. What I want is to run the heavy code in a background and send a response regardless of when the

auto execute a web service in falcon

天涯浪子 提交于 2019-12-08 04:11:48
问题 I have a function which registers my web-services to spring-eureka discovery server but it automatically de-registers it. to solve this problem, I thought to make a function which will automatically execute in few seconds and register my service again and again. Please suggest what to do and if u have a better approach to encounter this problem that will be great. 回答1: We can make another program which will ping the health check URL of my web server. responsePythonAPI = requests.request("GET"

falcon, AttributeError: 'API' object has no attribute 'create'

人走茶凉 提交于 2019-12-05 23:32:53
I'm trying test my falcon routes, but tests always failed, and looks like I make all things right. my app.py import falcon from resources.static import StaticResource api = falcon.API() api.add_route('/', StaticResource()) and my test directory tests/static.py from falcon import testing import pytest from app import api @pytest.fixture(scope='module') def client(): # Assume the hypothetical `myapp` package has a # function called `create()` to initialize and # return a `falcon.API` instance. return testing.TestClient(api.create()) def test_get_message(client): result = client.simulate_get('/')

SQLAlchemy and Falcon - session initialization

时光总嘲笑我的痴心妄想 提交于 2019-12-03 17:15:10
问题 I'm wondering where the best place would be to create a scoped session for use in falcon. From reading the flask-sqlalchemy code, it, in a round about way, does something like this: from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker try: from greenlet import get_current as get_ident except ImportError: try: from thread import get_ident except ImportError: from _thread import get_ident connection_uri = 'postgresql://postgres:@localhost:5432/db' engine

Python falcon and async operations

一个人想着一个人 提交于 2019-12-03 15:41:27
I am writing an API using python3 + falcon combination. There are lot of places in methods where I can send a reply to a client but because of some heavy code which does DB, i/o operations, etc it has to wait until the heavy part ends. For example: class APIHandler: def on_get(self, req, resp): response = "Hello" #Some heavy code resp.body(response) I could send "Hello" at the first line of code. What I want is to run the heavy code in a background and send a response regardless of when the heavy part finishes. Falcon does not have any built-in async capabilities but they mention it can be

SQLAlchemy and Falcon - session initialization

帅比萌擦擦* 提交于 2019-12-03 05:42:23
I'm wondering where the best place would be to create a scoped session for use in falcon. From reading the flask-sqlalchemy code, it, in a round about way, does something like this: from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker try: from greenlet import get_current as get_ident except ImportError: try: from thread import get_ident except ImportError: from _thread import get_ident connection_uri = 'postgresql://postgres:@localhost:5432/db' engine = create_engine(connection_uri) session_factory = sessionmaker(bind=engine) session_cls = scoped