【问题标题】:Converting a cURL to pyCurl equivalent将 cURL 转换为等效的 pyCurl
【发布时间】:2020-07-29 22:49:40
【问题描述】:

我有一个使用 cURL 的补丁请求,现在我想在 python 中使用它:

curl -X Patch -H "content-type: application/json" -d '{"activation": {"mode":"activate_immediate"},"transport_params":[{"destination_ip":"239.255.255.50","destination_port": 5004, "rtp_enabled": True, "source_ip": "192.168.10.115","source_port":"auto"}]}' http://ip:port/x-nmos/connection/v1.2/single/uuid/staged

任何人都可以帮助我使用 pyCurl 等效项或我可以使用 python 执行此操作的任何其他方式吗?

【问题讨论】:

标签: python json curl pycurl


【解决方案1】:

我建议您使用request 库而不是@Z4-tier 提到的pyCurl。试试:

import requests
headers = {"content-type": "application/json"}
data = {"activation": {"mode":"activate_immediate"},"transport_params":[{"destination_ip":"239.255.255.50","destination_port": 5004, "rtp_enabled": True, "source_ip": "192.168.10.115","source_port":"auto"}]}
url = "http://IP:PORT/x-nmos/connection/v1.0/single/UUID/staged"
resquest = requests.patch(url = url, data = data, headers = headers)

由于 ip 或端口错误,我无法完成请求。确保请求正文正确!

【讨论】:

  • 抱歉,由于安全问题,我无法共享 IP、PORT 和 UUID。我之前实际上尝试过requests,我得到<Response [200]>,但是当我尝试打印响应的内容时,它是空的。据我所知,响应的内容应该包含更新的参数。您是否知道可能导致问题的原因。
猜你喜欢
  • 2014-05-13
  • 1970-01-01
  • 1970-01-01
  • 2020-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多