Google App Engine: from six.moves import http_clie

2019-01-29 05:55发布

问题:

Okie dokie,

I'm trying to get Google's Dialogflow python API working with Google App Engine, and I seem to be running into issues when I run the application. I have pip installed dialogflow to a lib folder and added the lib folder through the app.yaml file. I keep running into an error where it says that it can't find 'six.moves.' Very new to this (app engine in general), so please tell me if I have something setup wrong.

I've read a few other threads with no luck. This won't work locally or deployed.

below are my app.yaml file:

runtime: python27
api_version: 1
threadsafe: true
service: basic-npl-ui

handlers:
- url: /img
  static_dir: img

- url: /javascript
  static_dir: javascript

- url: /css
  static_dir: css

- url: /.*
  script: main.app



env_variables:
  GAE_USE_SOCKETS_HTTPLIB: 'anyvalue'

libraries:
- name: jinja2
  version: latest
- name: webapp2
  version: latest
- name: ssl
  version: latest
- name: grpcio
  version: latest

and here's my error log (local development):

Traceback (most recent call last):
  File "/Users/AVD1WIP/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Users/AVD1WIP/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Users/AVD1WIP/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/Users/AVD1WIP/Documents/Orca_interns/NLP/basic_ui_app/main.py", line 28, in <module>
    from src.dialog_response_util import DialogflowResponseUtil
  File "/Users/AVD1WIP/Documents/Orca_interns/NLP/basic_ui_app/src/dialog_response_util.py", line 2, in <module>
    import dialogflow
  File "/Users/AVD1WIP/Documents/Orca_interns/NLP/basic_ui_app/lib/dialogflow/__init__.py", line 17, in <module>
    from dialogflow_v2 import AgentsClient
  File "/Users/AVD1WIP/Documents/Orca_interns/NLP/basic_ui_app/lib/dialogflow_v2/__init__.py", line 18, in <module>
    from dialogflow_v2.gapic import agents_client
  File "/Users/AVD1WIP/Documents/Orca_interns/NLP/basic_ui_app/lib/dialogflow_v2/gapic/agents_client.py", line 19, in <module>
    import google.api_core.gapic_v1.client_info
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/api_core/gapic_v1/__init__.py", line 16, in <module>
    from google.api_core.gapic_v1 import config
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/api_core/gapic_v1/config.py", line 26, in <module>
    from google.api_core import exceptions
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/google/api_core/exceptions.py", line 26, in <module>
    from six.moves import http_client
ImportError: No module named moves
INFO     2018-06-08 20:20:19,020 module.py:846] basic-npl-ui: "GET / HTTP/1.1" 500 -

回答1:

The traceback indicates that you have some dependencies not installed in your app's lib directory, they're picked up from your local python installation libraries. Note the .../python2.7/site-packages/google/api_core/gapic_v1 path in there.

You need to install all your app's dependencies in your app's lib dir, like mentioned in here.



回答2:

I had this problem too, make sure you "vendor in" all your dependencies, e.g.

pip install -t lib six==1.9.0

To resolve this error, I had to specify the version to match the one used in my local installation of python libraries added by the gcloud tool