如何将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无法识别它。
答案 0 :(得分:1)
在bash中,您转义了json的引号
在Python中,您不需要
data = {'userName' : 'exampleuser',
'password': 'examplepass'}
然后,您正在发送json,所以用json=data
代替data=data