Python GCP:在本地创建Client()对象

Python GCP:在本地创建Client()对象,python,python-3.x,logging,google-cloud-platform,stackdriver,Python,Python 3.x,Logging,Google Cloud Platform,Stackdriver,我有一个类,用于记录到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=se

我有一个类,用于记录到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)

当在谷歌云上运行时,它可以无缝工作。但是,当在本地运行时,它会在
CREDS=google.cloud.logging.Client(project=project,credentials=service\u account.credentials.from\u service\u account\u file(“/path/to/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
回溯(最近一次呼叫最后一次):
文件“/Users/daudn/Documents/clean_space/tgs_workflow/utils/logger.py”,第27行,在
GoogleLogger类(CloudLoggingHandler):
GoogleLogger中的文件“/Users/daudn/Documents/clean_space/tgs_workflow/utils/logger.py”,第36行
project=project,credentials=service\u account.credentials.from\u service\u account\u文件(local\u或\u gcp())
文件“/usr/local/lib/python3.7/site packages/google/cloud/logging/client.py”,第123行,在__
self.\u connection=连接(self,client\u info=client\u info)
文件“/usr/local/lib/python3.7/site packages/google/cloud/logging/_http.py”,第39行,在__
超级(连接,自我)。\uuuu初始化\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
TypeError:\uuuu init\uuuuuu()接受2个位置参数,但给出了3个

谷歌在此更改中添加了
客户端信息
参数:


我怀疑您在GCP环境中运行的是较新版本的Google Cloud Python SDK,而在本地环境中运行的是较旧版本。

当它崩溃时,您会遇到什么错误?@MicahCarrick编辑并添加了问题的回溯。您运行的是哪一版本的
Google Cloud core
pip show google cloud core
版本:0.24.1
@MicahCarrick我将更新此内容,并与您联系。我觉得你可能是对的,因为我的计算引擎实例上有1.1版。现在就测试这个!谢谢你,我没有想过要检查版本,这是修复!