gpt4 book ai didi

python - 部署到 App Engine 标准环境时如何修复 'ImportError: cannot import name base'?

转载 作者:太空宇宙 更新时间:2023-11-03 20:55:57 24 4
gpt4 key购买 nike

我创建了一个简单的 Google App Engine 应用程序,可与 Google 文档 API 配合使用。

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

但是,当我从 Google Cloud SDK 部署到 App Engine 标准环境时,出现以下错误:

'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 模块和对象已正确安装。请注意,在 App Engine Python 运行时环境中,必须将 Python 客户端库提供到您的应用程序中,因为它们未安装在应用程序中。

此处讨论了更多专门针对 Google Docs API 的引用资料[1]。

另请确保您已通过 [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

关于python - 部署到 App Engine 标准环境时如何修复 'ImportError: cannot import name base'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56028927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com