我有解go server組json它收到它。當(dāng)我使用 時(shí)它有效,curl但在 . 的情況下失敗python。去服務(wù)器解組代碼:type Data struct { Namespace string `json:"namespace"` ContainerId string `json:"containerId"`}func notify(w http.ResponseWriter, r *http.Request) { decoder := json.NewDecoder(r.Body) var data Data err := decoder.Decode(&data) if err != nil { glog.Errorf("Failed to decode the request json %s \n", err.Error()) return } ...}如果我執(zhí)行 curl 命令,它會毫無怨言地工作:curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data '{"namespace": "default", "containerId": "2f7c58d399f2dc35fa1be2abea19301c8e74973ddd72f55a778babf01db5ac26"}' http://mysvc:8080/notify但是如果我對它做同樣的事情Python就會抱怨:jsonPrep['containerId'] = "2f7c58d399f2dc35fa1be2abea19301c8e74973ddd72f55a778babf01db5ac26"jsonPrep['namespace'] = "default" headers = {'Content-type': 'application/json', 'Accept': 'application/json'}r = requests.post('http://mysvc:8080/notify', json=json.dumps(jsonPrep), headers=headers)抱怨go server:E1026 15:49:48.974117 1 main.go:59] Failed to decode the request json json: cannot unmarshal string into Go value of type main.Data當(dāng)我curl在python.誰能幫我找出問題所在?
從 bash 到 GO 服務(wù)器的 REST post 查詢有效但對于 Python 失敗
12345678_0001
2023-05-02 10:13:52