[英]Python - TypeError: super(type, obj): obj must be an instance or subtype of type?
[英]Azure event hub - TypeError: super(type, obj): obj must be an instance or subtype of type
Python版本3.7.1 uamqp-1.1.0
請幫助我們, init的 uamqp / client.py,第453行中出現此錯誤:
超級(SendClient,自我)。 init (TypeError:super(type,obj):obj必須是類型的實例或子類型
由於sender = client.add_sender(partition="0")
這是代碼:
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
非常感謝 !!
Github上的相關問題: https : //github.com/Azure/azure-event-hubs-python/issues/93
有一個SO線程super(type,obj):obj必須是類型的實例或子類型 ,答案會引入很多情況,這些情況將導致與您的情況相同。
在搜索Azure/azure-event-hubs-python
和Azure/azure-uamqp-python
的源代碼之后,我認為您的問題是由uamqp/client.py#L470
以下代碼引起的,與以下代碼的答案有關@Eldamir發布的上方的SO線程。
super(SendClient, self).__init__(
target,
auth=auth,
client_name=client_name,
debug=debug,
error_policy=error_policy,
keep_alive_interval=keep_alive_interval,
**kwargs)
另一種有趣的方式是,如果分支的合並復制了該類,則在文件中,您有兩個相同名稱的定義,例如
class A(Foo): def __init__(self): super(A, self).__init__() #... class A(Foo): def __init__(self): super(A, self).__init__() #...
如果您嘗試通過對A的第一個定義的靜態引用創建實例,則一旦它嘗試在init方法內部調用super,A就會引用A的第二個定義,因為它已被覆蓋。 解決方案(當然是)是刪除該類的重復定義,因此它不會被覆蓋。
這似乎是永遠不會發生的事情,但這只是在我身上發生了,當時我沒有對兩個分支的合並給予足夠的關注。 我的測試失敗了,並顯示了問題中描述的錯誤消息,所以我認為我將把發現保留在這里,即使它不能完全回答特定問題。
因此,我想您定義了一個名為SendClient
的類,它導致與uamqp/client.py
SendClient
類發生名稱沖突。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.