天青事件毂 - 类型错误:超级(类型,OBJ):OBJ必须是实例或类型的子类型

问题描述 投票:0回答:1

Python版本3.7.1 uamqp-1.1.0

帮助我们请,我们在uamqp / client.py,线453,在初始化此错误:

超级(SendClient,自我)的.init(类型错误:超级(类型,OBJ):OBJ必须是实例或类型的子类型

它的发生是因为qazxsw的POI

下面是代码:

sender = client.add_sender(partition="0")

非常感谢 !!

在Github上相关的问题:import sys import logging import datetime import time import os from azure.eventhub import EventHubClient, Sender, EventData logger = logging.getLogger("azure") ADDRESS = "amqps://xxx.servicebus.windows.net/xxx" USER = "xxx" KEY = "xxx" try: if not ADDRESS: raise ValueError("No EventHubs URL supplied.") # Create Event Hubs client client = EventHubClient(ADDRESS, debug=False, username=USER, password=KEY) sender = client.add_sender(partition="0") #self = <class 'uamqp.client.SendClient'> client.run() try: start_time = time.time() for i in range(10): print("Sending message: {}".format(i)) #sender.send(EventData()) except: raise finally: end_time = time.time() client.stop() run_time = end_time - start_time logger.info("Runtime: {} seconds".format(run_time)) except KeyboardInterrupt: pass

python python-3.x azure azure-eventhub azure-eventhub-capture
1个回答
0
投票

有一个SO线程https://github.com/Azure/azure-event-hubs-python/issues/93其答案引进许多情况下,这将导致问题,因为你一样。

我搜索super(type, obj): obj must be an instance or subtype of typeAzure/azure-event-hubs-python的源代码后,我觉得你的问题是由下面的代码中Azure/azure-uamqp-python其中涉及到的SO线程上述职位由@Eldamir的答案引起的。

uamqp/client.py#L470

另一个有趣的方法是,如果分支合并已经复制了类,因此该文件在你有相同的名称,例如两个定义

    super(SendClient, self).__init__(
        target,
        auth=auth,
        client_name=client_name,
        debug=debug,
        error_policy=error_policy,
        keep_alive_interval=keep_alive_interval,
        **kwargs)

如果试图从静态参考A的第一个定义创建一个实例,一旦它试图超打电话,init方法里,A将指的第二个定义,因为它已被覆盖。该解决方案 - ofcourse - 是消除类的重复定义,所以它不会被覆盖。

这看起来象是绝对不会发生的,但它只是发生在我身上,当时我并没有给予足够的关注两个分支的合并。我的测试,在这个问题描述的错误消息失败了,所以我想我会离开我的发现在这里,即使它不完全回答具体问题。

所以我想有被你这导致与class A(Foo): def __init__(self): super(A, self).__init__() #... class A(Foo): def __init__(self): super(A, self).__init__() #... SendClient类的名称冲突定义的类名为SendClient

© www.soinside.com 2019 - 2024. All rights reserved.