不工作样本基本

时间:2013-11-22 21:42:52

标签: python api endpoints-proto-datastore

我正在使用Google端点与http://endpoints-proto-datastore.appspot.com/

中端点 - 原型数据存储的基本示例一起工作

这是我的文件widgettiny_api.py

import endpoints

from google.appengine.ext import ndb
from protorpc import remote

from endpoints_proto_datastore.ndb import EndpointsModel



class Noticia(EndpointsModel):
    _message_fields_schema = ('id', 'titulo', 'contenido', 'creado')

    titulo = ndb.StringProperty()
    contenido = ndb.StringProperty()
    url_imagen = ndb.StringProperty()
    url = ndb.StringProperty()
    creado = ndb.DateTimeProperty(auto_now_add=True)


@endpoints.api(
    name='WidgetTinyApi',
    version='v1',
    description='API usada para consumir las noticias desde el cliente android o widget.')
class WidgetTinyApi(remote.Service):

    @Noticia.method(
        path="noticia",
        http_method="POST",
        name="noticia.insert")
    def NoticiaInsert(self, my_model):
        my_model.put()
        return my_model


    @Noticia.method(
        request_fields=('id',),
        path='noticia/{id}',
        http_method='GET',
        name='noticia.get')
    def NoticiaGet(self, my_model):
        if not my_model.from_datastore:
            raise endpoints.NotFoundException('Noticia no encontrada')
        return my_model


    @Noticia.query_method(
        path="noticias",
        name="noticia.list")
    def NoticiaList(self, query):
        return query


APPLICATION = endpoints.api_server([WidgetTinyApi], restricted=False)

我打开链接/ _ah / api / explorer。我收到了这个错误:

INFO     2013-11-22 16:24:28,992 module.py:608] default: "POST /_ah/spi/BackendService.getApiConfigs HTTP/1.1" 200 2957
ERROR    2013-11-22 16:24:29,354 discovery_api_proxy.py:55] Discovery API proxy failed on /_ah/api/discovery/v1/apis/generate/directory with 400.

Request: {"configs": ["{\"description\": \"API usada para consumir las noticias desde el cliente android o widget.\", \"abstract\": false, \"name\": \"WidgetTinyApi\", \"descriptor\": {\"methods\": {\"WidgetTinyApi.NoticiaList\": {\"response\": {\"$ref\": \"NoticiaCollection\"}}, \"WidgetTinyApi.NoticiaInsert\": {\"request\": {\"$ref\": \"Noticia\"}, \"response\": {\"$ref\": \"Noticia\"}}}, \"schemas\": {\"NoticiaCollection\": {\"type\": \"object\", \"id\": \"NoticiaCollection\", \"properties\": {\"nextPageToken\": {\"type\": \"string\"}, \"items\": {\"items\": {\"$ref\": \"Noticia\"}, \"type\": \"array\"}}}, \"Noticia\": {\"type\": \"object\", \"id\": \"Noticia\", \"properties\": {\"contenido\": {\"type\": \"string\"}, \"titulo\": {\"type\": \"string\"}, \"url_imagen\": {\"type\": \"string\"}, \"url\": {\"type\": \"string\"}, \"created\": {\"type\": \"string\"}}}}}, \"version\": \"v1\", \"extends\": \"thirdParty.api\", \"defaultVersion\": true, \"root\": \"http://localhost:20999/_ah/api\", \"adapter\": {\"bns\": \"http://localhost:20999/_ah/spi\", \"type\": \"lily\", \"deadline\": 10.0}, \"methods\": {\"widgetTinyApi.noticia.insert\": {\"scopes\": [\"https://www.googleapis.com/auth/userinfo.email\"], \"clientIds\": [\"292824132082.apps.googleusercontent.com\"], \"rosyMethod\": \"WidgetTinyApi.NoticiaInsert\", \"request\": {\"body\": \"autoTemplate(backendRequest)\", \"bodyName\": \"resource\"}, \"authLevel\": \"NONE\", \"httpMethod\": \"POST\", \"path\": \"noticia\", \"response\": {\"body\": \"autoTemplate(backendResponse)\", \"bodyName\": \"resource\"}}, \"widgetTinyApi.noticia.list\": {\"scopes\": [\"https://www.googleapis.com/auth/userinfo.email\"], \"clientIds\": [\"292824132082.apps.googleusercontent.com\"], \"rosyMethod\": \"WidgetTinyApi.NoticiaList\", \"request\": {\"body\": \"empty\"}, \"authLevel\": \"NONE\", \"httpMethod\": \"GET\", \"path\": \"noticias\", \"response\": {\"body\": \"autoTemplate(backendResponse)\", \"bodyName\": \"resource\"}}}}"]}

Response: {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }
}

ERROR    2013-11-22 16:24:29,355 discovery_service.py:137] Failed to get API directory
INFO     2013-11-22 16:24:29,355 module.py:608] default: "GET /_ah/api/discovery/v1/apis HTTP/1.1" 404 9

错误是什么?

1 个答案:

答案 0 :(得分:4)

name='WidgetTinyApi'无效。你需要一个小写的值。

来自documentation

  

名称值:

     
      
  • 必须以小写字母开头。
  •   
  • 必须与正则表达式[a-z]+[A-Za-z0-9]*匹配。
  •