api.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:iris 作者: linkedin 项目源码 文件源码
def on_post(self, req, resp):
        post_dict = parse_qs(req.context['body'])
        if 'Body' not in post_dict:
            raise HTTPBadRequest('SMS body not found', 'Missing Body argument in post body')

        if 'From' not in post_dict:
            raise HTTPBadRequest('From argument not found', 'Missing From in post body')
        source = post_dict['From'][0]
        body = post_dict['Body'][0]
        try:
            msg_id, content = utils.parse_response(body.strip(), 'sms', source)
        except (ValueError, IndexError):
            raise HTTPBadRequest('Invalid response', 'failed to parse response')

        try:
            _, response = self.handle_user_response('sms', msg_id, source, content)
        except Exception:
            logger.exception('Failed to handle sms response: %s' % body)
            raise
        else:
            resp.status = HTTP_200
            resp.body = ujson.dumps({'app_response': response})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号