It seems I have another JSON problem, this time when sending to a REST service. I am using Flask-Restful .
api.add_resource(Records, '/rest/records/<string:email>/<string:password>/<string:last_sync_date>') parser = reqparse.RequestParser() parser.add_argument('record_date', type=str) parser.add_argument('records', type=str) parser.add_argument('rating', type=str) parser.add_argument('notes', type=str) class Records(Resource): def post(self, email, password, last_sync_date): args = parser.parse_args() records = args['records']
Unit test:
resource_fields = { 'record_date': fields.String, 'rating': fields.Integer, 'notes': fields.String, 'last_updated': fields.DateTime, } records = {"records":[]} records["records"].append(marshal(record1, resource_fields)) rv = self.app.post('/rest/records/{0}/{1}/{2}'.format(email, password, sync_date), data=json.dumps(records))
json.dumps (entries):
str: {"records": [{"rating": 1, "notes": null, "last_updated": "Tue, 15 Oct 2013 15:52:44 -0000", "record_date": "2013-10-15 15:52:44.746815"}]}
Why args['records'] No, where do I explicitly send it by wire?
UPDATE:
The strange part is when I send one object, all its dandies. So strange:
record = dict(record_date=record1.record_date, rating=record1.rating, notes=record1.notes, last_updated=record1.last_updated) rv = self.app.post('/rest/records/{0}/{1}/{2}'.format(email, password, sync_date), data=record)
arg
{'records': None, 'notes': None, 'task': None, 'record_date': '2013-10-15 16:48:40.662744', 'rating': '1'}