Google Cloud Endpoints Python快速入门回显示例问题 [英] Google Cloud Endpoints Python Quickstart echo sample issue

查看:252
本文介绍了Google Cloud Endpoints Python快速入门回显示例问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python标准环境快速入门中,端点方法test_api_key返回503服务不可用.当与dev_appser.py一起运行并部署了API时,该错误会在API资源管理器中发生.它的代码是:

In the python standard environment quickstart, the endpoints method test_api_key returns a 503 Service Unavailable. The error occurs in the API Explorer when run with dev_appser.py and when the API is deployed. The code for it is:

import endpoints
from protorpc import message_types
from protorpc import messages
from protorpc import remote

class TestResponse(messages.Message):
    content = messages.StringField(1)

@endpoints.api(name='practice', version='v1', description='My Practice API')
class PracticeApi(remote.Service):

    @endpoints.method(
        message_types.VoidMessage,
        TestResponse,
        path='test/getApiKey',
        http_method='GET',
        name='test_api_key')
    def test_api_key(self, request):
        return TestResponse(content=request.get_unrecognized_field_info('key'))

api = endpoints.api_server([PracticeApi])

我对.get_unrecocoizedized_field_info('key')不太了解,所以我不确定是什么问题?谢谢.

I don't have a good understanding of .get_unrecognized_field_info('key') so I am not sure what the issue is? Thanks.

推荐答案

有三件事造成了503错误.

There were three things that were creating the 503 error.

首先,我需要制作方法或整个Api

Firstly, I needed to make the method or entire Api require an Api Key. In this case I just applied it to the entire Api:

@endpoints.api(name='practice', version='v1', api_key_required=True)
class PracticeApi(remote.Service):

第二,在云控制台中生成Api密钥后,我需要在部署密钥之前,将密钥放入openapi.json文件.

Secondly, after I generated the Api Key in the cloud console I needed to put the Key into the openapi.json file before deploying it.

最后,我仍然收到验证错误:

Lastly, I was still getting a validation error:

ValidationError: Expected type <type 'unicode'> for field content, found (u'My Api Key', Variant(STRING, 9)) (type <type 'tuple'>)

get_unrecocoizedized_field_info()函数返回(值的元组,变体).响应未预期有元组,因此我将方法更新为仅显示值:

The get_unrecognized_field_info() function returns a tuple of (value, variant). A tuple was not expected by the response so I updated the method to only show value:

    def test_api_key(self, request):
        return TestResponse(content=request.get_unrecognized_field_info('key')[0])

这篇关于Google Cloud Endpoints Python快速入门回显示例问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆