0
我嘗試在使用HTTPSConnection的python中轉換curl命令。python HTTPSConnection curl -g參數
起源curl命令是:
curl -X DELETE \
-H "X-LC-Id: "id" \
-H "X-LC-Key: "key" \
-G \
--data-urlencode 'limit=10' \
https://xxx/1.1/logs
下面是一個有效的解決方案:
connection = httplib.HTTPSConnection("https://xxx")
connection.connect()
connection.request(
"GET",
"/1.1/logs?limit=" + 10,
json.dumps({}),
{
"X-LC-Id" : "id",
"X-LC-Key" : "key",
}
)
results = json.loads(connection.getresponse().read())
return results
這正常工作與10個返回結果。
但是,以下不工作:
connection = httplib.HTTPSConnection("https://xxx")
connection.connect()
connection.request(
"GET",
"/1.1/logs",
json.dumps({"limit": "10"}),
{
"X-LC-Id" : "id",
"X-LC-Key" : "key",
}
)
results = json.loads(connection.getresponse().read())
return results
該解決方案從服務器,而不是10
我應該在哪裏放捲曲-g提起這些參數在使用時返回的所有郵件HTTPSConnection而不必做出這樣的請求字符串:
"/1.1/logs?limit=" + 10 + "&aaa=" + aaa + "&bbb=" + bbb + ...
任何建議表示讚賞,感謝:)