无法在我的 VS 代码中导入 eventgrid 模块,我已在 require.txt 中添加了所有模块,并从我的 cmd 安装了 pip。
另外,下面是我正在寻找和尝试的python函数:
def publish_event():
# authenticate client
credential = AzureKeyCredential(key)
client = EventGridPublisherClient(endpoint, credential)
custom_schema_event = {
"customSubject": "sample",
"customEventType": "sample.event",
"customDataVersion": "2.0",
"customId": uuid.uuid4(),
"customEventTime": dt.datetime.now(UTC()).isoformat(),
"customData": "sample data"
}
# publish events
for _ in range(3):
event_list = [] # list of events to publish
# create events and append to list
for j in range(randint(1, 3)):
event_list.append(custom_schema_event)
# publish list of events
client.send(event_list)
print("Batch of size {} published".format(len(event_list)))
time.sleep(randint(1, 5))
if name == '__main__':
publish_event()
我不确定这是否是实现此目标的正确方法,正在寻找解决模块问题和发布事件的更好方法。
帮助将不胜感激!