【问题标题】:Python Error When Accessing JSON Data From AngularJS POST从 AngularJS POST 访问 JSON 数据时出现 Python 错误
【发布时间】:2014-10-07 06:45:05
【问题描述】:

我正在尝试通过 POST 将数据发送到 python 脚本,但无法读取它。用户界面在 AngularJS 中。我见过类似的问题,但他们要么不使用 AngularJS,要么不使用 POST。

Angular 代码:

$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 但无济于事。我在这里错过了什么?

【问题讨论】:

    标签: javascript python angularjs post


    【解决方案1】:

    问题在于您尝试以 JSON 格式发送的数据。您要发送的数据是什么?它是一个 Python 对象吗? This 可以帮助你。那些是纯字符串吗?字典?他们有无效字符吗?您可以使用JSON Lint 来检查有效性。

    【讨论】:

    • javascript 数组,字符串化
    猜你喜欢
    • 2020-04-05
    • 1970-01-01
    • 1970-01-01
    • 2016-07-09
    • 1970-01-01
    • 2017-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多