我有一个类,用于记录到StackDriver。你知道吗
from google.cloud.logging.handlers import CloudLoggingHandler
from google.oauth2 import service_account
class GoogleLogger(CloudLoggingHandler):
CREDS = google.cloud.logging.Client(
project=PROJECT, credentials=service_account.Credentials.from_service_account_file("/path/to/creds"))
def __init__(self, client=CREDS):
super(GoogleLogger, self).__init__(client)
当在google云上运行时,它可以无缝地工作。但是,当在本地运行时,它在CREDS = google.cloud.logging.Client(project=PROJECT, credentials=service_account.Credentials.from_service_account_file("/path/to/creds"))
处中断
我的密码全断了。你知道吗
问题:如果不在云上,有没有方法跳过实例化这个类?像条件类?你知道吗
或
问题:有什么方法可以让这项工作在本地进行吗?应该有用。我给它creds和项目,根据StackDriver docs如果我给它project+creds,它应该在本地和GCP中工作?你知道吗
当它中断时,这是回溯:
Traceback (most recent call last):
File "/Users/daudn/Documents/clean_space/tgs_workflow/utils/logger.py", line 27, in <module>
class GoogleLogger(CloudLoggingHandler):
File "/Users/daudn/Documents/clean_space/tgs_workflow/utils/logger.py", line 36, in GoogleLogger
project=PROJECT, credentials=service_account.Credentials.from_service_account_file(local_or_gcp()))
File "/usr/local/lib/python3.7/site-packages/google/cloud/logging/client.py", line 123, in __init__
self._connection = Connection(self, client_info=client_info)
File "/usr/local/lib/python3.7/site-packages/google/cloud/logging/_http.py", line 39, in __init__
super(Connection, self).__init__(client, client_info)
TypeError: __init__() takes 2 positional arguments but 3 were given
Google在这个更改中添加了
client_info
参数:https://github.com/googleapis/google-cloud-python/pull/7849/files#diff-340196d499e9d0eea25cd457f53bfa42L31我怀疑您在GCP环境中运行的是较新版本的Google Cloud Python SDK,而在本地环境中运行的是较旧版本。你知道吗
相关问题 更多 >
编程相关推荐