我有这个类,它用于登录到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"))中断
而我的整个密码都被破解了。
问题:如果没有在云中实例化这个类,那么有没有跳过实例化的方法?像个有条件的类?
或
问题:有什么办法在本地工作吗?应该管用的。我给它的信用和项目,根据StackDriver文档,如果我给它的项目+信用,它应该工作在本地以及在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发布于 2020-01-03 12:35:43
谷歌在此更改中添加了client_info参数:https://github.com/googleapis/google-cloud-python/pull/7849/files#diff-340196d499e9d0eea25cd457f53bfa42L31
我怀疑您正在GCP环境中运行的更新版本,在本地环境中运行一个较旧的版本。
https://stackoverflow.com/questions/59578320
复制相似问题