Accessing API using Python -
i trying retrieve data api , receiving
'set' object has no attribute 'items'
this api.py , have import views
import json import urllib import urllib2 import pycurl def get_resources(request, filter, endpoint, lookup): headers = {'x-auth-token:%s' % request.user.token, 'content-type:application/json'} data = urllib.urlencode(filter) url = endpoint+lookup req = urllib2.request(url, data, headers) response = urllib2.urlopen(req) result = json.loads(response.read()) return result
and views.py this
def indexview(request): resources = json.dumps(get_resources(request,{}, api_endpoint, '/v2/meters')) return httpresponse(resources, mimetype='application/json')
i know doing wrong here, hope me thanks.
the line:
headers = {'x-auth-token:%s' % request.user.token, 'content-type:application/json'}
defines set
. , should dictionary (which has :
somewhere in after follows value key before :
)
Comments
Post a Comment