Coinbase Pro API使用Python拥有AuthenticatedClient对象后,cbpro Python模块不会处理身份验证

2024-06-16 14:33:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在使用coinbase pro api的cbpro python模块。在我的相关课程中,我有以下代码

def authenticate(self):
    try:
        print("Connecting to the coinbase pro.")
        self.client = cbpro.AuthenticatedClient(constants.cbpro_pubkey,
                                                constants.cbpro_secret,
                                                constants.cbpro_passphrase,
                                                api_url="https://api-public.sandbox.pro.coinbase.com"
                                                )
        self.authenticated = True
        print("Connected to the coinbase pro.")

    except Exception as err:
        print("An error occurred while authenticating to the coinbase pro:", str(err))
        self.authenticated = False
       

此代码可以工作,但每当我禁用internet连接时,它都会在self.client语句之后继续运行。我只需要看看我是否连接到api。换句话说,self.authenticated = True语句是不正确的,在代码的其他部分,当我尝试运行这个经过身份验证的客户机的某些方法时,它给出了预期的连接错误

当互联网被禁用时,这种例外情况永远不起作用。在拥有AuthenticatedClient对象(这里是self.client)之后,有什么方法可以确定它的身份验证吗


Tags: theto代码selfclientapitruecbpro