gpt4 book ai didi

python - 从 google.cloud.logging_v2 导入类型 ImportError : cannot import name types

转载 作者:太空宇宙 更新时间:2023-11-04 02:15:58 24 4
gpt4 key购买 nike

我正在开发一个在 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 session ,进入 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 client for Stackdriver logging .这不是为 GAE 第一代(即 Python 2.7)应用程序设计/支持的,因为此运行时已经集成了自己的(定制的)stackdriver 日志记录。

来自 Supported environments :

The following VM instances support Stackdriver Logging using their own software, possibly including custom versions or configurations of the Stackdriver Logging agent. Manually installing the Stackdriver Logging agent on them is not supported:

关于python - 从 google.cloud.logging_v2 导入类型 ImportError : cannot import name types,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52656114/

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