【发布时间】:2020-11-03 03:07:29
【问题描述】:
我有一个使用 Echo 库在 Go 中编写的端点。我正在尝试通过 python 脚本发布数据,但收到“绑定元素必须是结构”错误。
来自端点的代码,我将请求主体绑定到变量(Go lang):
// get body from request
requestBody := make(map[string]interface{})
if err := c.Bind(&requestBody); err != nil {
return err
}
Python 脚本:
data = {
"AED": {
"USD": 0.2719
},
"ARS": {
"USD": 0.0142
}
}
headers = {
"Authorization": # my_jwt_token,
"API-Key": # my api_key
}
requests.put(url, data=payload, headers=headers)
if not response.ok:
raise Exception("Failed to update")
return result.status_code
错误信息:
{"logType":"application","msg":"Status: 400, Error: code=400, message=binding element must be a struct, Title: Client Error, Message: binding element must be a struct, Detail: ","action":"Error Handler","level":"error","timestamp":"2020-07-13T13:39:19-07:00"}
为什么会这样?我可以使用 Postman 发送完全相同的 Payload,它工作正常,但使用 python 请求库发送 PUT 请求不起作用。
【问题讨论】:
标签: python go struct request put