1

When attempting to pull in the grpcio library along with Cloud Endpoints Framework, it causes an error when running it through dev_appserver.py. When these changes are pushed to Google Cloud Platform App Engine the error does not present itself.

I have tried changing the versions of google-endpoints, grpcio, and six, but none of the combinations resolved the error. I have run into the error on both Windows and Ubuntu.

Error

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

Recreating the issue

Make sure you have Google Cloud SDK installed.

Clone the python-docs-samples repository: https://github.com/GoogleCloudPlatform/python-docs-samples.git

Navigate into echo sample

cd python-docs-samples/appengine/standard/endpoints-frameworks-v2/echo

Start dev_appserver

dev_appserver.py app.yaml

Send a POST test to make sure it works.

curl -d '{"content":"time"}' -H "Content-Type: application/json" -X POST http://localhost:8080/_ah/api/echo/v1/echo

With the echo application working, now install grpcio with the version GCP uses.

pip install grpcio==1.0.0

Edit the app.yaml file to include the grpcio library, so your file will look like this.

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]

Start dev_appserver.py again.

dev_appserver.py app.yaml

Send the POST again.

curl -d '{"content":"time"}' -H "Content-Type: application/json" -X POST http://localhost:8080/_ah/api/echo/v1/echo

The error I placed above should show up in the output of the dev_appserver.py.

  • Try to also request the GAE-provided `six` library in your `app.yaml`, it probably has customisations compared to the standard one picked up from your local python installation. – Dan Cornilescu Jun 27 '18 at 17:26
  • @DanCornilescu Thank you for the suggestion. Unfortunately, adding the six reference (below or above the grpcio reference because I cannot remember if order matters) had no affect. – Justin Wesley Jun 27 '18 at 17:37
  • Were you following [this](https://cloud.google.com/endpoints/docs/frameworks/python/get-started-frameworks-python) tutorial? Also try adding to `requirements.txt` library `six==1.11.0` – komarkovich Jun 28 '18 at 15:21
  • @komarkovich Thank you for the suggestion. No, I just used the example as an easy way for others to recreate the issue. Unfortunately, installing version 1.11.0 of six didn't help. – Justin Wesley Jun 29 '18 at 14:29
  • Try and follow the [tutorial](https://cloud.google.com/endpoints/docs/frameworks/python/get-started-frameworks-python) with installing `grpcio` to see if the issue still persists. – komarkovich Jun 30 '18 at 10:00

0 Answers0