Accessing API using Python
Question: I was trying to retrieve data from an API and i was receiving

**'set' object has no attribute 'items'**

This is my api.py and i have import it to my 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 my views.py is like this

    
    
    def indexView(request):
        resources = json.dumps(get_resources(request,{}, api_endpoint, '/v2/meters'))
        return HttpResponse(resources, mimetype='application/json')
    

I know that i was doing wrong here, I hope someone who could help me thanks.


Answer: The line:

    
    
    headers = {'X-Auth-Token:%s' % request.user.token,
               'Content-Type:application/json'}
    

defines a [`set`](http://docs.python.org/2/library/stdtypes.html#set). And it
should probably be a dictionary (which has `:` somewhere in after which
follows the value for the key before the `:`)

