当尝试将grpcio库与Cloud Endpoints Framework一起拉入时,通过dev_appserver.py运行它会导致错误。将这些更改推送到Google Cloud Platform App Engine时,错误不会自行出现。
我尝试过更改google-endpoint,grpcio和6的版本,但是没有一种组合可以解决该错误。我在Windows和Ubuntu上都遇到了错误。
Traceback (most recent call last):
File "C:\Users\jwesley\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Users\jwesley\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "C:\Users\jwesley\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "C:\Users\jwesley\code_store\gcp_python_sample\python-docs-samples\appengine\standard\endpoints-frameworks-v2\echo\main.py", line 19, in <module>
import endpoints
File "C:\Users\jwesley\code_store\gcp_python_sample\python-docs-samples\appengine\standard\endpoints-frameworks-v2\echo\lib\endpoints\__init__.py", line 27, in <module>
from .apiserving import *
File "C:\Users\jwesley\code_store\gcp_python_sample\python-docs-samples\appengine\standard\endpoints-frameworks-v2\echo\lib\endpoints\apiserving.py", line 76, in <module>
from endpoints_management.control import client as control_client
File "C:\Users\jwesley\code_store\gcp_python_sample\python-docs-samples\appengine\standard\endpoints-frameworks-v2\echo\lib\endpoints_management\__init__.py", line 17, in <module>
from . import auth, config, control, gen
File "C:\Users\jwesley\code_store\gcp_python_sample\python-docs-samples\appengine\standard\endpoints-frameworks-v2\echo\lib\endpoints_management\control\__init__.py", line 19, in <module>
from ..gen import servicecontrol_v1_messages as sc_messages
File "C:\Users\jwesley\code_store\gcp_python_sample\python-docs-samples\appengine\standard\endpoints-frameworks-v2\echo\lib\endpoints_management\gen\servicecontrol_v1_messages.py", line 23, in <module>
from apitools.base.py import encoding
File "C:\Users\jwesley\code_store\gcp_python_sample\python-docs-samples\appengine\standard\endpoints-frameworks-v2\echo\lib\apitools\base\py\__init__.py", line 21, in <module>
from apitools.base.py.base_api import *
File "C:\Users\jwesley\code_store\gcp_python_sample\python-docs-samples\appengine\standard\endpoints-frameworks-v2\echo\lib\apitools\base\py\base_api.py", line 27, in <module>
from six.moves import http_client
ImportError: No module named moves
确保已安装Google Cloud SDK。
克隆python-docs-samples存储库: https://github.com/GoogleCloudPlatform/python-docs-samples.git
导航回波样本
cd python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo
启动dev_appserver
dev_appserver.py app.yaml
发送POST测试以确保其正常工作。
curl -d '{"content":"time"}' -H "Content-Type: application/json" -X POST http://localhost:8080/_ah/api/echo/v1/echo
在echo应用程序正常运行的情况下,现在安装具有GCP使用版本的grpcio。
pip install grpcio==1.0.0
编辑app.yaml文件以包含grpcio库,这样您的文件将如下所示。
runtime: python27
threadsafe: true
api_version: 1
basic_scaling:
max_instances: 2
#[START_EXCLUDE]
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*\.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?\..*$
- ^(.*/)?setuptools/script \(dev\).tmpl$
#[END_EXCLUDE]
handlers:
# The endpoints handler must be mapped to /_ah/api.
- url: /_ah/api/.*
script: main.api
libraries:
- name: pycrypto
version: 2.6
- name: ssl
version: 2.7.11
- name: grpcio
version: "latest"
# [START env_vars]
env_variables:
# The following values are to be replaced by information from the output of
# 'gcloud endpoints services deploy swagger.json' command.
ENDPOINTS_SERVICE_NAME: YOUR-PROJECT-ID.appspot.com
ENDPOINTS_SERVICE_VERSION: 2016-08-01r0
# [END env_vars]
再次启动dev_appserver.py。
dev_appserver.py app.yaml
再次发送POST。
curl -d '{"content":"time"}' -H "Content-Type: application/json" -X POST http://localhost:8080/_ah/api/echo/v1/echo
我在上面放置的错误应该显示在dev_appserver.py的输出中。