从AngularJS POST访问JSON数据时发生Python错误

Python Error When Accessing JSON Data From AngularJS POST

本文关键字:Python 错误 数据 AngularJS POST 访问 JSON      更新时间:2023-09-26

我试图通过POST将数据发送到python脚本,但无法读取。UI在AngularJS中。我看到过类似的问题,但他们要么没有使用AngularJS,要么没有使用POST。

角度代码:

$scope.send = function(){
        $data = {
            "tableData":$scope.personsSelected
        }
        $postData = JSON.stringify($data);
        Services.post('testbed.cgi', $postData);
    }

Python代码:

formData = cgi.FieldStorage()
print json.dumps(formData)

错误消息:

TypeError: FieldStorage(None, None, []) is not JSON serializable

我曾尝试将内容类型设置为application/x-www-form-urlencoded,但没有成功。我在这里错过了什么?

问题在于您试图以JSON形式发送的数据。你想发送的数据是什么?它是Python对象吗?这可能会对你有所帮助。那些是普通的绳子吗?词典它们有无效字符吗?您可以使用JSON Lint来检查有效性。