第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 Python 將 jsonfiles 發(fā)送到 EventHub

使用 Python 將 jsonfiles 發(fā)送到 EventHub

慕尼黑5688855 2022-05-24 16:28:15
我需要使用 Python 將 jsonfiles 從我的文件夾發(fā)送到 azure-EventHubimport jsonfrom azure.eventhub import EventHubClient, Sender, EventData# Address can be in either of these formats:# "amqps://<URL-encoded-SAS-policy>:<URL-encoded-SAS-key>@<mynamespace>.servicebus.windows.net/myeventhub"# "amqps://<mynamespace>.servicebus.windows.net/myeventhub"# SAS policy and key are not required if they are encoded in the URLADDRESS = "amqps://xxxxxxxxxxxx.servicebus.windows.net/import"# SAS policy and key are not required if they are encoded in the URLUSER = "xxx"KEY = "xxxxxxxxxxxxxx"# Create an Event Hubs clientclient = EventHubClient(ADDRESS, debug=False, username=USER, password=KEY)# Add a sender to the clientsender = client.add_sender(partition="0")# Run the Event Hub clientclient.run()# Send jsonfile one by one to the event hub from below foldersender.send(EventData("C:/Users/shef123/Desktop/"))我的代碼不起作用,因?yàn)槲覄傞_始學(xué)習(xí) python。任何人都可以幫我解決這個(gè)問題。
查看完整描述

2 回答

?
絕地?zé)o雙

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊

這里重要的是EventDataobject 只需要string 或 bytes。Python SDK 不會(huì)為您讀取文件,只會(huì)將該文件路徑作為原始數(shù)據(jù)字符串并將該字符串發(fā)送到事件中心。

因此,您需要做的是打開文件并將內(nèi)容加載到字節(jié)數(shù)組中,然后將字節(jié)傳遞給EventData構(gòu)造函數(shù) -- EventData(body=loaded_bytes)。請注意,根據(jù)您選擇的層級(基本/標(biāo)準(zhǔn)) ,活動(dòng)規(guī)模有配額限制。


值得注意的是,azure-eventhub v5 已于 2020 年 1 月 GAed。

它在 pypi 上可用:https ://pypi.org/project/azure-eventhub/

請按照從 v1 到 v5 的遷移指南遷移您的程序。

還有一個(gè)示例文件夾示例供您開始使用。


查看完整回答
反對 回復(fù) 2022-05-24
?
PIPIONE

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個(gè)贊

問題在于您嘗試將數(shù)據(jù)發(fā)送到事件中心的方式。您不能直接調(diào)用此函數(shù)并傳遞文件夾以處理文件,如下所示:

sender.send(EventData("C:/Users/shef123/Desktop/"))

您可以查看此鏈接以讀取 json 文件:

https://www.simplifiedpython.net/python-read-json-file/

您可以從文件夾中讀取 JSON 文件,并且可以使用類似的代碼一一發(fā)送。

您可以在 beloe repo 中找到與發(fā)送數(shù)據(jù)相關(guān)的代碼:

https://github.com/Azure/azure-event-hubs-python/blob/master/examples/send_async.py


查看完整回答
反對 回復(fù) 2022-05-24
  • 2 回答
  • 0 關(guān)注
  • 167 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號