简体   繁体   中英

Python Error When Accessing JSON Data From AngularJS POST

I am trying to send data to a python script via POST but unable to read it. The UI is in AngularJS. I have seen similar questions but they are either not using AngularJS or not using POST.

The Angular code:

$scope.send = function(){

        $data = {
            "tableData":$scope.personsSelected
        }

        $postData = JSON.stringify($data);
        Services.post('testbed.cgi', $postData);
    }

Python Code:

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

Error Message:

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

I have tried setting the content type to application/x-www-form-urlencoded but to no avail. What am I missing here?

The issue is with the data you are trying to send as JSON. Whats the data you are trying to send? Is it a Python object? This may help you. Are those plain strings? Dictionary? Do they have invalid characters? You can use JSON Lint to check validity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM