2

I'm experiencing some difficulties when parsing a JSON object sent from AngularJS to Python (Google App Engine).

The AngularJS code:

var article = { name: 'car' };
$http.put("articles", article);

The python code:

# -*- coding: UTF-8 -*-

import os
import webapp2
import logging
import json 

class ArticleHandler(webapp2.RequestHandler):

    def put(self):
        data = self.request

        logging.error(data)
        #x = json.dumps(data)   
        #y = json.loads(data)

The error-log returns {"name":"car"}

json.dumps(data) raises: TypeError(repr(o) + " is not JSON serializable")

and

json.loads(data) raises: TypeError: expected string or buffer

Any help is appreciated

1
  • Somewhat embarrassingly, the solution was simple json.loads(self.request.body) Commented Sep 27, 2013 at 22:08

1 Answer 1

1

You are trying to parse a Request object as json data. Try parsing the body instead:

json.loads(self.request.body)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.