Python AttributeError: 'super' object has no attribute 'testnet', however the attribute appears when __dict__ is called on super?

Python AttributeError: 'super' object has no attribute 'testnet', however the attribute appears when __dict__ is called on super?

from binance.client import Client
from binance.websockets import BinanceSocketManager

class Binance_Data(Client):
    def __init__(self, api_key, api_secret, requests_params=None, tld='us'):
        super().__init__(api_key, api_secret, requests_params=None, tld='us')

    def data_stream_test(self, data):
        print('------------------')
        print(f"Event Title: {data['e']}")
        print(f"Closing Price: {data['c']}")
        print(convert_unix_to_utc(data['E']))
        print('------------------')

    def data_stream(self):
        ds = BinanceSocketManager(super())
        conn_key = ds.start_symbol_ticker_socket('XLMUSDT', data_stream_test)
        ds.start()

我有这个 class 继承了 binance 客户端从它的 API 读取数据。然后我调用 BinanceSocketManager,它接收一个 binance Client 的实例。但是,当我 运行 程序时,出现以下错误:

AttributeError: 'super' object has no attribute 'testnet'

但是当我在测试方法中打印 super().__dict__ 以获取属性时,它显示 testnet 作为 super:

的属性
{...,'testnet': False, 'timestamp_offset': -8}

我调用父类方法没有问题,例如super().get_ticker(),但是我在这里遇到错误。

super() 不是 return class 本身,而是调用 superclass 方法的代理,已讨论 .

而不是 super() 试试 self.