Scot, Thanks for the reply. OK I've gotten down to the point to where I 
have my version of your json_data in your code below, but I'm not sure I 
understand exactly what your code is doing, after you have the json_data 
variable contents. In my case the first object of response data that I'm 
trying to use is a list of two items, with each item containing multiple 
keys and internal or sub objects within them. 
Can you please explain your code after you have the json_data variable 
formatted further? I'm guessing you're doing some kind of further required 
conversion of the data, and if so I'm not sure I understand why those 
conversions are necessary and being done.
My current piece of response data that I'm trying to work with looks like 
this(when I print it in my command prompt window):


[
    {
        u'status': u'complete', 
        u'parameters': 
        {
            u'enrollment_term_id': u'', 
            u'extra_text': u'Term: All Terms;'
        }, 
        u'file_url': 
u'https://stchas.test.instructure.com/accounts/1/files/7787/download', 
        u'attachment': 
        {
            u'display_name': 
u'grade_export_csv_10_Feb_2014_40_18363-0.csv', 
            u'unlock_at': None, 
            u'url': 
u'https://stchas.test.instructure.com/files/7787/download?download_frd=1&verifier=nEU8FRMgfMaCFUK0NoIXiGMaQj0M
xWWJ4BM7PrMU', 
            u'created_at': u'2014-02-10T15:26:24Z', 
            u'updated_at': u'2014-02-10T15:26:24Z', 
            u'filename': 
u'1392045984_664__grade_export_csv_10_Feb_2014_40_18363-0.csv', 
            u'lock_at': None, 
            u'thumbnail_url': None, 
            u'hidden_for_user': False, 
            u'locked': False, 
            u'hidden': False, 
            u'locked_for_user': False, 
            u'content-type': u'text/csv', 
            u'id': 7787, 
            u'size': 4744
        }, 
        u'report': u'grade_export_csv', 
        u'progress': 100, 
        u'id': 40
    }, 
    {
        u'status': u'complete', 
        u'parameters': 
        {
            u'enrollment_term_id': u'', 
            u'extra_text': u'Term: All Terms;'
        }, 
        u'file_url': 
u'https://stchas.test.instructure.com/accounts/1/files/1033/download', 
        u'attachment': 
        {
            u'display_name': u'grade_export_csv_22_Oct_2013_2_27551-0.csv', 
            u'unlock_at': None, 
            u'url': 
u'https://stchas.test.instructure.com/files/1033/download?download_frd=1&verifier=uhw0oyfb0f3m4GtgJAVvwQkRlDfK0kCbg200SIu4',
 

            u'created_at': u'2013-10-22T19:15:45Z', 
            u'updated_at': u'2013-10-22T19:15:45Z', 
            u'filename': u'grade_export_csv_22_Oct_2013_2_27551-0.csv', 
            u'lock_at': None, 
            u'thumbnail_url': None, 
            u'hidden_for_user':False, 
            u'locked': False, 
            u'hidden': False, 
            u'locked_for_user': False, 
            u'content-type': u'text/csv', 
            u'id': 1033, 
            u'size': 395
        }, 
        u'report': u'grade_export_csv',
        u'progress': 100, 
        u'id': 2
    }
]

So far I've tried to access the objects inside the list like I normally 
would in python using indexing for the list items like this:

lstobjct = rspnslist[index]

but so far all I've gotten from this is an "exceptions.AttributeError". 

Thanks again for the help.  

On Friday, February 6, 2015 at 9:54:03 AM UTC-6, Scot Hacker wrote:

> On Thursday, February 5, 2015 at 11:10:32 AM UTC-8, Henry Versemann wrote:
>>
>> I have a django view (django v. 1.7 ; python v. 2.7.8) which currently 
>> and successfully sends a request to an api, and receives a good response 
>> back. I'm sending and receiving using the 'requests' library (v. 2.4.3). 
>> Now in addition to sending the raw response data back in an HttpResponse I 
>> would also like to strip out some of the data and create a summary report 
>> of it, to also send back in my HttpResponse.
>>
> What Larry said - you need to convert the javascript data format into a 
> python data format. json.loads() will do that for you. Here's a working 
> example: 
>
>
> import json
>
> def get_nyt_news():
>     # NYT API data
>     response = requests.get(
>         '
> http://api.nytimes.com/svc/mostpopular/v2/mostshared/all-sections/7.json?api-key={apikey}'.format(apikey=settings.NYT_API_KEY)
>         )
>
>     json_data = json.loads(response.text)
>     data = json_data['results'][0:4]
>
>     # Rewrite data to conform internal links
>     for d in data:
>         d['get_absolute_url'] = d['url']
>
>     return {'object_list': data}
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/119dfb90-58ca-48fa-a457-ec95f2eec171%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to