Python falcon 模块,HTTP_202 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用falcon.HTTP_202

项目:EVA    作者:metno    | 项目源码 | 文件源码
def on_post(self, req, resp, method=None):
        if not self.has_param(req, 'uuid'):
            raise falcon.HTTPBadRequest("Please provide the 'uuid' parameter, specifying which Productstatus resource to process.")

        if not self.has_param(req, 'adapter'):
            raise falcon.HTTPBadRequest("Please provide the 'adapter' parameter, specifying which adapter should process the resource.")

        try:
            self.exec_functions(req, resp, method, ['productinstance', 'datainstance'])
            resp.status = falcon.HTTP_202

        except productstatus.exceptions.NotFoundException as e:
            raise falcon.HTTPBadRequest('The Productstatus resource could not be found: %s' % e)

        except productstatus.exceptions.ServiceUnavailableException as e:
            raise falcon.HTTPServiceUnavailable('An error occurred when retrieving Productstatus resources: %s' % e)
项目:plex-watched-sync    作者:fiLLLip    | 项目源码 | 文件源码
def on_put(self, req, resp, account_id):
        """Handles PUT requests"""
        try:
            raw_json = req.stream.read()
        except Exception as ex:
            raise falcon.HTTPError(falcon.HTTP_400,
                                   'Error',
                                   ex.message)

        try:
            result_json = json.loads(raw_json, encoding='utf-8')
        except ValueError:
            raise falcon.HTTPError(falcon.HTTP_400,
                                   'Malformed JSON',
                                   'Could not decode the request body. The '
                                   'JSON was incorrect.')

        items = result_json['watched']
        result = Actions.add_watched_to_account(account_id, items)
        resp.status = falcon.HTTP_202
        jsonresp = {'account_id': account_id, 'tried_to_add': items, 'added': result}
        resp.body = json.dumps(jsonresp)
项目:falcon-api-redis    作者:kentsay    | 项目源码 | 文件源码
def on_post(self, req, resp, doc_index):
        try:
            raw_json = req.stream.read()
        except Exception as ex:
            raise falcon.HTTPError(falcon.HTTP_400,
                'Error',
                ex.message)
        try:
            result_json = json.loads(raw_json, encoding='utf-8')
        except ValueError:
            raise falcon.HTTPError(falcon.HTTP_400,
                'Malformed JSON',
                'Could not decode the request body. The JSON was incorrect.')

        """
        Enqueueing write request as jobs into document_write queue
        and processing them in the background with workers.
        """
        q = Queue('document_write', connection=self.db.connection())
        job = q.enqueue_call(
            func=postDocument, args=(result_json, doc_index), result_ttl=5000
        )
        LOG.info('POST request ' + str(job.get_id()))

        resp.status = falcon.HTTP_202
        resp.body = json.dumps(result_json, encoding='utf-8')


    # This function handles DELETE reuqests