KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to post a JSON object through a POST. I'm trying to do it as follows: import json, urllib, urllib2 filename = 'test.json' race_id = 2530 f = open(filename, 'r') fdata = json.loads(f.read()) f.close() prefix = 'localhost:8000' count = 0 for points in fdata['positions'].iteritems(): print '--' + str(count) + '--------' url = 'http://'+prefix+'/api/points' parameters = {'point_data': json.dumps(points), 'race_id': race_id} data = urllib.urlencode(parameters) print data request = urllib2.Request(url, data) response = urllib2.urlopen(request) count += 1 break; print 'Finished adding points' The data is then received on the other end (I'm using Google App Engine) with: point_data = json.load(self.request.get('point_data')) But I get the following error: ERROR 2010-06-30 15:08:05,367 __init__.py:391] 'unicode' object has no attribute 'read' Traceback (most recent call last): File "/home/ian/workspace/google_appengine/google/appengine/ext/webapp/__init__.py", line 513, in __call__ handler.post(*groups) File "/home/ian/workspace/codebase/track_builder/geo-api.py", line 276, in post point_data = json.load(self.request.get('point_data')) File "/home/ian/workspace/google_appengine/lib/django/django/utils/simplejson/__init__.py", line 208, in load return cls(encoding=encoding, **kw).decode(fp.read()) AttributeError: 'unicode' object has no attribute 'read' INFO 2010-06-30 15:08:05,376 dev_appserver.py:3266] "POST /api/points HTTP/1.1" 500 - Any ideas on how to fix this? EDIT: As requested here is an example of the points: (u'1276859700', { u'24': { u'tempc': u'-22.7', u'gpsq': u'1', u'altm': u'65527', u'hd': u'112', u'hdop': u'0.93', u'bton': u'0', u'maxv': u'20.15', u'idit': u'1', u'satc
Tags (comma-separated)
Save Edits
Cancel