2013-11-22 47 views
3

我正在與谷歌端點與端點-原數據存儲的基本例子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 

什麼是錯誤?

回答

4

name='WidgetTinyApi'無效。你需要一個小寫的值。

documentation

名稱值:

  • 必須以小寫字母開頭。
  • 必須匹配正則表達式[a-z]+[A-Za-z0-9]*
+0

我有同樣的問題。對我來說,這是一些錯誤的版本號 – 0xAffe

0

我在執行中遇到同樣的錯誤。我已經檢查過,該API的名稱與正則表達式匹配,並且以低位字符開頭。

同樣@ 0xAffe評論,我檢查版本號是'v1'。

繼承人我的代碼:

import logging 
import endpoints 
from models.inmobiliaria import SalesExecutive 
from protorpc import remote 


@endpoints.api(name='juustoRestApi', 
       version='v1', 
       description='Enpoints API for the Juus.to app') 
class JuustoRestApi(remote.Service): 

    @SalesExecutive.method(path='executive/create', 
          http_method='POST', 
          name='executive.create') 
    def create_sales_executive(self, executive): 
     executive.put() 
     return executive 

    @SalesExecutive.query_method(query_fields=('email', 'password'), 
               path='executive/login', 
               name='executive.login') 
    def login(self, query): 
     logging.info(query) 
     return query 

application = endpoints.api_server([JuustoRestApi], restricted=False)