将 cURL 转换为 pyCurl 等价物
Converting a cURL to pyCurl equivalent
我有一个使用 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 执行此操作的任何其他方式吗?
我建议您使用 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 或端口错误,我无法完成请求。确保请求正文是正确的!
我有一个使用 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 执行此操作的任何其他方式吗?
我建议您使用 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 或端口错误,我无法完成请求。确保请求正文是正确的!