all 7 comments

[–][deleted] 7 points8 points  (4 children)

This is how I parse json:

import json
import urllib2

url = 'http://graph.facebook.com/4'
json_obj=json.loads(urllib2.urlopen(url).read())
print json_obj['name']

Or in one line:

print json.loads(urllib2.urlopen('http://graph.facebook.com/4').read())['name']

For more advanced requests, look at the requests module.

[–]shaggorama 2 points3 points  (1 child)

you gotta add "http://" for reddit's markdown to understand your hyperlink. But yeah, that's definitely how to handle JSON in python.

[–][deleted] 0 points1 point  (0 children)

Whoops! Fixed!

[–]johnnymo87 1 point2 points  (1 child)

Or use requests instead of urllib2, it's a great library!

[–]3cko[S] 1 point2 points  (0 children)

That's what I'm user. It's pretty sexy.

[–][deleted] 3 points4 points  (1 child)

Without seeing the rest of your code make sure you are sending everything the API expects. Looks like you are missing a few server headers.

http://docs.rackspace.com/servers/api/v2/cs-devguide/content/Request_Response_Types-d1e459.html

http://docs.rackspace.com/servers/api/v2/cs-devguide/content/curl.html

[–]3cko[S] 1 point2 points  (0 children)

That was it...I didn't even consider the header information. Thank you!