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

问题描述

我有以下 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)

解决方法

这有效吗? 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