【发布时间】:2014-03-26 08:57:21
【问题描述】:
当我尝试将谷歌云端点集成到现有项目中时,我收到此错误:
ImportError: No module named endpoints
我已经在我的 app.yaml 文件中添加了端点。端点 api 文件在外部使用其自己的 app.yaml 文件,但从项目目录中运行时会出现错误。为简单起见,我将所有 api 调用路由到“endpoints_api.py”。也许我错过了什么。
这是我的目录设置:
-project
-handlers
-media
-templates
-webapp2_extras
__init__.py
app.yaml
main.py
endpoints_api.py
这是我的 app.yaml 文件:
application: project-aplha
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
# Endpoints Api
- url: /_ah/spi/.*
script: endpoints_api.APPLICATION
- url: /favicon\.ico
static_files: media/favicon.ico
upload: media/favicon.ico
- url: /media
static_dir: media
# Main Script
- url: /.*
script: main.APPLICATION
libraries:
- name: endpoints
version: 1.0
- name: webapp2
version: latest
- name: jinja2
version: latest
- name: pycrypto
version: latest
还有一个处理程序类的示例(如果重要的话):
class SignupHandler(base.BaseHandler):
def get(self):
return self.render_template('sighup.html')
def post(self):
name = self.request.get('name')
email = self.request.get('email')
password = self.request.get('password')
也许还有 endpoints_api.py 文件:
import endpoints
from google.appengine.ext import ndb
from protorpc import messages
from protorpc import message_types
from protorpc import remote
class Task(messages.Message):
name = messages.StringField(1, required=True)
owner = messages.StringField(2)
class TaskModel(ndb.Model):
name = ndb.StringProperty(required=True)
owner = ndb.StringProperty()
@endpoints.api(name='tasks', version='v1',
description='API for Task Management')
class TaskApi(remote.Service):
@endpoints.method(Task, Task,
name='task.insert',
path='task',
http_method='POST')
def insert_task(self, request):
TaskModel(name=request.name, owner=request.owner).put()
return request
APPLICATION = endpoints.api_server([TaskApi])
【问题讨论】:
-
您还没有真正提供任何足够接近的信息让人们除了猜测之外做任何事情。例如,您是否在 app.yaml 中启用了端点,您在 app.yaml 中的处理程序是什么样的等等......
-
上述上下文表明端点已添加到 app.yaml 文件中。我正在路由所有“/_ah/api/explorer”链接以使用endpoints_api.py 而不是main.py。在上面添加 app.yaml 和处理程序示例
-
为什么你的APPLICATION是大写的?
-
如何在本地运行项目?
-
将应用程序更改为应用程序。还更改了措辞以使事情更清晰。
标签: python google-app-engine google-cloud-endpoints