为什么此调用对Curl的Postman有效,但对Python不起作用

时间:2019-06-19 04:47:35

标签: python curl postman

Curl代码对python无效

试图从curl变为python

curl --location --request PUT "https://api.getpostman.com/environments/XXXXX-YYYYYY-ZZZZ-BBBB-AAAA-ZZZZZZ?apikey=12334567890" \
  --header "Content-Type: application/json" \
  --data "{
    \"environment\": {
        \"values\": [
            {\"key\": \"url\", \"value\": \"http://10.12.30.131\"}
        ]
    }
}"



import requests
import json
url = 'https://api.getpostman.com/environments/XXXXX-YYYYYY-ZZZZ-BBBB-AAAA-ZZZZZZ?apikey=12334567890'
header = {"Content-type": "application/json"}
body = '{\"environment\": { \"name\": \"Prod - Deploy\", \"values\": [ {\"key\": \"url\", \"value\": \"http://10.12.30.131\"}]}}'
response = requests.put(url, data=json.dumps(body), headers=header)

print(response.status_code)
print(response.text)

期待200条回复

1 个答案:

答案 0 :(得分:0)

主体应为主体='{“ environment \”:{“ name \”:“产品-部署\”,“ values \”:[{“ key \”:“ url \”,“ value \” :“ http://10.12.30.131 \”},{“ key \”:“ appPath \”,“ value \”:“ footytips-apis-v1 \”}]}}''