0

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.

0

2 Answers 2

2

The line:

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

defines a set. And it should probably be a dictionary (which has : somewhere in after which follows the value for the key before the :)

Sign up to request clarification or add additional context in comments.

Comments

0

Try something like that:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.