python - how to get urllib2 to return data as an array -


not sure if possible, if awesome.

my code is:

url = "https://*mydomain*.zendesk.com/api/v2/organizations/*{id}*/tags.json" req = urllib2.request(url) password_manager = urllib2.httppasswordmgrwithdefaultrealm() password_manager.add_password(none, url, 'example@domain.com', 'password') auth_manager = urllib2.httpbasicauthhandler(password_manager) opener = urllib2.build_opener(auth_manager) urllib2.install_opener(opener) response = urllib2.urlopen(req) tagsa = response.read() print tagsa 

now data returned is:

{"tags":[]} 

the api call returns following

{ tags: [] } 

however trying access list doesn't work seems treat tagsa string. treat list check if 'tags' empty.

any appreciated!!!

you need load json string python dictionary via json.loads():

import json  ...  tagsa = json.loads(response.read()) print tagsa['tags'] 

or, pass response json.load() (thanks @j.f. sebastian's comment):

tagsa = json.load(response) print tagsa['tags'] 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -