如何将这个PUT curl转换为python请求?

时间:2019-12-05 14:27:49

标签: python curl

如何将CURL PUT请求转换为python请求:

curl

curl -X PUT "https://example.com" -H  "accept: application/json" -H  "Content-Type: application/json-patch+json" -d "{  \"userName\": \"exampleuser\",  \"password\": \"examplepass\"}"

目前有

headers = {"accept": "application/json",
           "Content-Type": "application/json-patch+json"}
data = {'\"userName\"': '\"exampleuser\"',
        '\"password\"': '\"examplepass\"'}

response = requests.put(url=url, data=data, headers=headers)
print(response)

当前收到401响应。不幸的是,curl converter无法识别它。

1 个答案:

答案 0 :(得分:1)

在bash中,您转义了json的引号

在Python中,您不需要

data = {'userName' : 'exampleuser',
    'password': 'examplepass'}

然后,您正在发送json,所以用json=data代替data=data