【问题标题】:Why does this call work to Postman from Curl but not Python为什么这个调用对 Curl 的 Postman 有效,但对 Python 无效
【发布时间】:2019-11-01 18:04:49
【问题描述】:

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 响应

【问题讨论】:

  • 为什么要转义body 中的双引号?单引号字符串可以包含纯双引号。 message = '"Hello", he said.'

标签: python curl postman


【解决方案1】:

正文应该是 body = '{"environment\": {"name\": "Prod - Deploy\", "values\": [{"key\": "url\", "value\" : "http://10.12.30.131\"}, {"key\": "appPath\", "value\": "footytips-apis-v1\"} ]}}'

【讨论】:

    猜你喜欢
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多