[英]What is the python requests equivalent of the following curl command
在ably.io上,他們有一個例子,可以使用以下curl請求將消息發布到頻道:
curl -X POST https://rest.ably.io/channels/channelname/messages \
-u "some_AP.aYYMcQ:VmGHauKOqo-35Zxo" \
-H "Content-Type: application/json" \
--data '{ "name": "greeting", "data": "example" }'
傳遞給-u的值是具有發布權限的API密鑰。 如何使用Python請求庫發出相同的帖子請求? 我搜索了文檔但找不到它。 注意這里沒有密碼,只有api密鑰。
提前致謝。
你可以用這個:
requests.post("https://rest.ably.io/channels/channelname/messages",
auth=('some_AP.aYYMcQ', 'VmGHauKOqo-35Zxo'), # Equivalent of -u
json={ "name": "greeting", "data": "example" }) # Equivalent of --data
使用json
選項時, -H
自動設置為Content-Type: application/json
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.