我正在 python 中使用 hug 编写一个 API,我无法将 JSON 字符串传递给我的函数使用的变量,然后它将被添加到数据库中。我正在使用 RestClient Firefox 插件来发送 POST 请求。
这是我的功能的样子:
@hug.post("/table")
def add_to_table(json_data):
jsondata = json.load(json_data)
my_func = My_Function(**jsondata) #adding to database using sqlalchemy
我的内容类型是:'Content-Type: application/json'
. 这是我在 RestClient 主体中的样子:
{"json_data": "
{ "name": "Jeff",
"phone": 123,
"gender": "male"
}
" }
截至目前使用此代码,我收到此错误:json.decoder.JSONDecodeError: Invalid control character at: line 1 column 16 (char 15)
谢谢。