来自镜像API的Google Glass callbackUrl帖子是空的?

2024-05-29 03:10:25 发布

您现在位置:Python中文网/ 问答频道 /正文

抱歉,因为我知道的唯一一个web开发是django/python类型的,并且可能犯了混淆我的代码习惯用法(REST vs django URL分派工作流)

我有一个URL处理程序,可以作为我的玻璃器皿订阅的回调URL。我正在向处理程序发送POST,但请求对象似乎为空。在

我确信我理解错了,但是有人能告诉我从一个POST通知到callbackURL获取“回复”信息的方向吗。在

我的URL处理程序是

class A600Handler(webapp2.RequestHandler):

def post(self):
    """Process the value of A600 received and return a plot"""
    # I am seeing this in my logs proving that I am getting a POST when glass replies
    logging.info("Received POST to logA600")
    # This is returning None
    my_collection = self.request.get("collection")
    logging.info(my_collection)
    # I also tried this but self.sequest.POST is empty '[]' and of type UnicodeMultiDict
    # json_request_data = json.loads(self.request.POST)


@util.auth_required
def get(self):
    """Process the value of A600 received and return a plot"""
    logging.info("Received GET to this logA600")

我定义了下面的URL处理程序,并且可以通过查看appengine日志来验证post函数是否在用户点击reply时得到“ping”。在

MAIN_ROUTES = [ ('/', MainHandler),('/logA600',A600Handler), ]

如何以用户发送的语音转录文本的形式提取有效载荷?。我不明白The "parse_notification" example given in the docs


Tags: andofthedjangoselfinfourl处理程序
2条回答

我也有这个问题的镜像API调用我的应用程序通知,这些通知是空的。我的应用程序运行在tomcat上,所以它是一个java堆栈。所有示例都是这样处理通知的:

BufferedReader notificationReader = new BufferedReader(
                new InputStreamReader(request.getInputStream()));
        String notificationString = "";

        // Count the lines as a very basic way to prevent Denial of Service
        // attacks
        int lines = 0;
        while (notificationReader.ready()) {
            notificationString += notificationReader.readLine();
            lines++;

            // No notification would ever be this long. Something is very wrong.
            if (lines > 1000) {
                throw new IOException(
                        "Attempted to parse notification payload that was unexpectedly long.");
            }
        }

        log.info("got raw notification " + notificationString);

对我来说,这总是记录为空。由于通知url必须是https,并且为了测试我不能使用IP地址,我设置了dyndns服务来指向我的本地主机:8080正在运行服务。这一切似乎都是可行的,但我怀疑dynns的工作方式是某种类型的转发或重定向,在这里post数据被删除。在

我该如何解决这一问题以促进地方发展?在

更新: 帮我解决了。 我发现在阅读请求之前关闭响应会导致请求输入流已关闭。移动这个

^{pr2}$

到我完全读入请求通知后变成一个字符串解决了这个问题。在

你试过^{}docs for ^{}状态

"If you need to access raw or non-form data posted in the request, access this through the HttpRequest.body attribute instead."

如果API在其post中没有使用表单数据,您可能会在request.body中找到内容。The docs to which you linked表示内容将作为JSON而不是表单数据(“包含JSON请求正文”)放入正文中。我会试试json.loads(request.body)。在

相关问题 更多 >

    热门问题