Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 885819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:58:13+00:00 2026-05-15T12:58:13+00:00

I’m trying to post a JSON object through a POST. I’m trying to do

  • 0

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': u'10',
        u'minv': u'20.15',
        u'lat': u'35.271993',
        u'btusr': u'0',
        u'lng': u'-121.845353',
        u'knots': u'7'
    },
    u'11': {
        u'tempc': u'13.0',
        u'gpsq': u'1',
        u'altm': u'65535',
        u'hd': u'130',
        u'hdop': u'0.84',
        u'bton': u'0',
        u'maxv': u'15.96',
        u'idit': u'1',
        u'satc': u'12',
        u'minv': u'15.88',
        u'lat': u'34.877815',
        u'btusr': u'0',
        u'lng': u'-121.386116',
        u'knots': u'8'
    }
}

EDIT 2:
Thanks to Daniel Roseman and Nick Johnson who both caught my error. I’ve changed

point_data = json.loads(self.request.get('point_data'))

This has solved the error but, now I’m getting:

ERROR    2010-06-30 16:07:29,807 __init__.py:391] 'list' object has no attribute 'iteritems'
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 255, in post
    for time, units in point_data.iteritems():
AttributeError: 'list' object has no attribute 'iteritems'
INFO     2010-06-30 16:07:29,816 dev_appserver.py:3266] "POST /api/points HTTP/1.1" 500 -

which relates to the following code:

class TrackPoint(webapp.RequestHandler):
    def post(self):
        point_data = json.loads(self.request.get('point_data'))
        race_id = self.request.get('race_id')
        added = []
        failed = []
        for time, units in point_data.iteritems():
            for unit, data in units.iteritems():
                ...

Any ideas on this one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:58:13+00:00Added an answer on May 15, 2026 at 12:58 pm

    It looks like self.request.get() is returning a unicode object rather than a file-like object. You could try using json.loads() instead of json.load().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.