[英]What is the python requests equivalent of the following curl command
On ably.io they have an example where one can use the following curl request to publish a message to a channel: 在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" }'
The value passed to -u is an API key that has publish privileges. 传递给-u的值是具有发布权限的API密钥。 How does one make the same post request using Python requests library?
如何使用Python请求库发出相同的帖子请求? I searched the documentation but could not find it.
我搜索了文档但找不到它。 Note there is no password here, only the api key.
注意这里没有密码,只有api密钥。
Thanks in advance. 提前致谢。
You could use this: 你可以用这个:
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
When you use the json
option, -H
is automatically set to Content-Type: application/json
. 使用
json
选项时, -H
自动设置为Content-Type: application/json
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.