【问题标题】:How to fix 'ImportError: cannot import name base' when deploying to app engine standard environment?部署到应用引擎标准环境时如何修复“ImportError:无法导入名称库”?
【发布时间】:2019-05-07 18:59:01
【问题描述】:

我创建了一个简单的 Google App Engine 应用程序,它与 Google docs api 配合使用。

它需要来自google.authapp_engine 模块(来自google.auth import app_engine),我已将其安装在/lib 文件夹中并将vendor.add('lib') 添加到appengine_config.py

但是,当我从谷歌云 SDK 部署到应用引擎标准环境时,我收到以下错误:

'importError: cannot import name base'

我也收到了错误:

'ImportError: No module named pyasn1.codec.der'

对于这两个问题,我加倍检查了基本模块和pyasn1.codec.der 模块是否确实存在于lib 文件夹中。在这两种情况下都是如此。

有人知道问题可能是什么吗?

from google.auth import app_engine
import googleapiclient.discovery

这里有完整的提示:

基础

Traceback (most recent call last):
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7679791231c143f9/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7679791231c143f9/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7679791231c143f9/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/main.py", line 23, in <module>
    from google.auth import app_engine
  File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/lib/google/auth/app_engine.py", line 29, in <module>
    from google.auth import crypt
  File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/lib/google/auth/crypt/__init__.py", line 38, in <module>
    from google.auth.crypt import base
ImportError: cannot import name base

pyasn1.codec.der

traceback (most recent call last):
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7679791231c143f9/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7679791231c143f9/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7679791231c143f9/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/main.py", line 23, in <module>
    from google.auth import app_engine
  File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/lib/google/auth/app_engine.py", line 29, in <module>
    from google.auth import crypt
  File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/lib/google/auth/crypt/__init__.py", line 39, in <module>
    from google.auth.crypt import rsa
  File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/lib/google/auth/crypt/rsa.py", line 27, in <module>
    from google.auth.crypt import _python_rsa
  File "/base/data/home/apps/e~emailtest69/20190507t182648.418021119853034691/lib/google/auth/crypt/_python_rsa.py", line 24, in <module>
    from pyasn1.codec.der import decoder
ImportError: No module named pyasn1.codec.der

【问题讨论】:

    标签: python google-app-engine google-docs-api


    【解决方案1】:

    确保 Python 模块和对象已正确安装。 请注意,在 App Engine Python 运行时环境中,必须将 Python 客户端库供应到您的应用程序中,因为它们并未安装在其中。

    此处[1] 讨论了更多针对 Google Docs API 的参考。

    还要确保您已通过 [2] 获得凭据:

    从 google.auth 导入 app_engine
    凭据 = app_engine.Credentials()

    由于错误来自 google.auth.crypt 模块,您也可以在此页面[3] 上查看更多信息。

    [1]https://developers.google.com/docs/api/how-tos/libraries#python
    [2]https://github.com/googleapis/google-auth-library-python/blob/master/docs/user-guide.rst#the-app-engine-standard-environment
    [3]https://google-auth.readthedocs.io/en/latest/reference/google.auth.crypt.html#module-google.auth.crypt

    【讨论】:

      【解决方案2】:

      我有同样的问题,我去“google”目录并手动删除“auth”。 跑完之后

      pip install google-auth
      

      它开始工作了。

      【讨论】:

        猜你喜欢
        • 2015-09-25
        • 2017-10-22
        • 2021-12-08
        • 2019-11-27
        • 2015-02-05
        • 2019-12-19
        • 1970-01-01
        • 2021-02-08
        相关资源
        最近更新 更多