【发布时间】:2019-03-10 09:36:29
【问题描述】:
我正在开发一个在 GAE 上运行的小应用程序。当我部署我的应用程序或尝试使用 virtualenv(根据文档)时,当我尝试访问该应用程序时,我会在 Cloud Platform 的日志中看到以下内容(它们在本地也相同):
File "/base/data/home/apps/d~my-project/gen-debug:413039252702584887/main.py", line 10, in <module>
from google.cloud import logging_v2
File "/base/data/home/apps/d~my-project/gen-debug:413039252702584887/lib/google/cloud/logging_v2/__init__.py", line 17, in <module>
from google.cloud.logging_v2 import types
ImportError: cannot import name types
引发此错误的代码如下所示:
from google.cloud import logging_v2
client = logging_v2.LoggingServiceV2Client()
c = client.list_log_entries(["my-project"], filter_='resource.type="global" AND jsonPayload.hello="there"')
l = list(c)
l1 = l[0]
desc, value = l1.ListFields()[1]
print desc.camelcase_name, dict(value.items())
非常奇怪的是,在 Google 中,我可以进入 Cloud Shell 会话,进入 ipython,并且这段代码完全可以工作。
me@cloudshell:~ (my-project)$ ipython2
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
Type "copyright", "credits" or "license" for more information.
IPython 5.8.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: from google.cloud import logging_v2
...: client = logging_v2.LoggingServiceV2Client()
...: c = client.list_log_entries(["my-project"], filter_='resource.type="global" AND jsonPayload.hello="there"')
...: l = list(c)
...: l1 = l[0]
...: desc, value = l1.ListFields()[1]
...: print desc.camelcase_name, dict(value.items())
...:
jsonPayload {u'hello': u'there'}
是什么导致在 GAE 上运行它与在 Google Cloud Shell 中运行它不同?此导入错误似乎是 Google 问题,但我不确定。
【问题讨论】:
标签: python google-app-engine google-cloud-logging