如何将特定的 CURL 请求转换为 Python

时间:2021-06-10 05:53:49

标签: python python-3.x curl python-requests pycurl

我有以下 Curl 请求:

curl -v --location --request POST 'http://127.0.0.1:8080/abc' \--header 'Content-Type: application/json' \--data-raw '{data}'

我尝试使用 pycurl 和 requests 命令。 也尝试放置标题,但没有用。

我尝试过的代码:

requests = "curl -v --location"

a = "http://127.0.0.1:8080/abc"

headers = {'Content-Type': 'application/json'}

r = requests.post(url=a, headers= headers , params=data)

1 个答案:

答案 0 :(得分:1)

这有效吗? https://curl.trillworks.com/

import requests

headers = {
    'Content-Type': 'application/json',
}

data = '{data}'

response = requests.post('http://127.0.0.1:8080/abc',
                         headers=headers,
                         data=data)

enter image description here