# Course 2 - Week 2 - Lab2 - Batch Data Processing from API

**URL:** <https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718>\
**Category:** Source Systems, Data Ingestion, and Pipelines\
**Tags:** week-module-2, coursera-platform\
**Created:** [October 15, 2024, 3:46pm UTC](https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718 "2024-10-15T15:46:22Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ricardo\_Lousada](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ricardo_lousada/32/51911_2.png) [@Ricardo\_Lousada](https://community.deeplearning.ai/u/Ricardo_Lousada)\
**Post date:** [October 15, 2024, 3:46pm UTC](https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718/1 "2024-10-15T15:46:22Z")

</div>

I’m having some doubts about this block of code:

```auto
if "None" in None:
                    # Call get_auth_header() function with the "access_token" from the token_response.
                    headers = None(
                        access_token=None["None"]
                    )
                    print("Token has been refreshed")
                    continue # Retry the request with the updated token
                else:
                    print("Failed to refresh token.")
                    return []

```

I’m not understanding the “None” in “” and also the headers part, can someone please give me a tip?

Thank you in advance for your time.

Ricardo.

---

<div class="post-metadata">

**Author:** ![Georgios](https://avatars.discourse-cdn.com/v4/letter/g/eb9ed0/32.png) [@Georgios](https://community.deeplearning.ai/u/Georgios)\
**Post date:** [October 15, 2024, 4:24pm UTC](https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718/2 "2024-10-15T16:24:57Z")

</div>

Hello @Ricardo_Lousada,  
This is the same step as before but this time your are refreshing your auth\_header if you get a 401 error. The 401 error means that your access\_token has expired after 60minutes:

if the access\_token in the token\_response you get in the previous line, then continue:

Call the get\_auth\_header() function with the access\_token[“access\_token”] from the token\_response.

Hope its helpful

---

<div class="post-metadata">

**Author:** ![Ricardo\_Lousada](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ricardo_lousada/32/51911_2.png) [@Ricardo\_Lousada](https://community.deeplearning.ai/u/Ricardo_Lousada)\
**Post date:** [October 18, 2024, 10:34am UTC](https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718/3 "2024-10-18T10:34:02Z")

</div>

Hi @Georgios, thanks for the help, I made it 🙂

---

<div class="post-metadata">

**Author:** ![Georgios](https://avatars.discourse-cdn.com/v4/letter/g/eb9ed0/32.png) [@Georgios](https://community.deeplearning.ai/u/Georgios)\
**Post date:** [October 18, 2024, 10:40am UTC](https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718/4 "2024-10-18T10:40:46Z")

</div>

@Ricardo_Lousada glad it fixed, thanks

---

<div class="post-metadata">

**Author:** ![vijaybhangale](https://avatars.discourse-cdn.com/v4/letter/v/13edae/32.png) [@vijaybhangale](https://community.deeplearning.ai/u/vijaybhangale)\
**Post date:** [September 7, 2025, 10:13pm UTC](https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718/5 "2025-09-07T22:13:55Z")

</div>

getting error as “AttributeError: ‘dict’ object has no attribute ‘albums’“ at # Use extend() method to add the albums’ items to the list of responses.

```
\# responses.None(response.None('None').None('None'))

responses.extend(response.albums('None').items('None'))

```

not sure what update needed here

error details:

--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[42], line 1 ----\> 1 responses = paginated\_new\_releases(endpoint\_request=get\_new\_releases, **2** url=URL\_NEW\_RELEASES, **3** access\_token=token.get(‘access\_token’), **4** offset=0, limit=20) Cell In[41], line 32, in paginated\_new\_releases(endpoint\_request, url, access\_token, offset, limit) **29** response = endpoint\_request(\*\*kwargs) **30** # Use extend() method to add the albums’ items to the list of responses. **31** # responses.None(response.None(‘None’).None(‘None’)) —\> 32 responses.extend(response.albums(‘None’).items(‘None’)) **33** # .items(‘None’)) **34** # Get the total number of the elements in albums and save it in the variable total\_elements. **35** total\_elements = responses.albums(‘None’).total(‘None’)

Code:  
{mentor edit: code removed}

---

<div class="post-metadata">

**Author:** ![Amir\_Zare](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/amir_zare/32/95275_2.png) [@Amir\_Zare](https://community.deeplearning.ai/u/Amir_Zare)\
**Post date:** [September 8, 2025, 5:53am UTC](https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718/6 "2025-09-08T05:53:46Z")

</div>

Hello @vijaybhangale

Your code contains a lot of “`None`"s. You are supposed to follow the instructions to replace these with the correct values and run the code cell afterwards.

---

<div class="post-metadata">

**Author:** ![vijaybhangale](https://avatars.discourse-cdn.com/v4/letter/v/13edae/32.png) [@vijaybhangale](https://community.deeplearning.ai/u/vijaybhangale)\
**Post date:** [September 9, 2025, 10:10pm UTC](https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718/7 "2025-09-09T22:10:07Z")

</div>

Hi @Amir_Zare : I update all “None” values.

7th instruction in the lab is

Inside the `while` loop do the following steps:

\* Update the `offset` value with the current value from the request you did plus the `limit` value.

What is mean by “current value“ here. There is no “current value” in the response mentioned @ [Web API Reference | Spotify for Developers](https://developer.spotify.com/documentation/web-api/reference/get-new-releases)

My assignment says “ **Deadline** Pass this assignment by Sep 11, 1:59 AM CDT”, what this deadlight means. If I don’t complete the assignment by 11th I will fail the course, I need to restart the course from the scratch or I need to redo whole week material again …

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [September 9, 2025, 11:36pm UTC](https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718/8 "2025-09-09T23:36:42Z")

</div>

The deadlines mean very little. They’re just reminders. You can ignore them, and they will reset automatically as necessary.

---

<div class="post-metadata">

**Author:** ![vijaybhangale](https://avatars.discourse-cdn.com/v4/letter/v/13edae/32.png) [@vijaybhangale](https://community.deeplearning.ai/u/vijaybhangale)\
**Post date:** [September 10, 2025, 5:07am UTC](https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718/9 "2025-09-10T05:07:10Z")

</div>

execution if going into infinite loop, always pulling first 20 elements with offset = 0 and limit =20, offset value is not increasing in the loop. Any hint why it is going to infinite loop

{mentor edit: code removed}

---

<div class="post-metadata">

**Author:** ![Georgios](https://avatars.discourse-cdn.com/v4/letter/g/eb9ed0/32.png) [@Georgios](https://community.deeplearning.ai/u/Georgios)\
**Post date:** [September 10, 2025, 12:30pm UTC](https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718/10 "2025-09-10T12:30:07Z")

</div>

Hello @vijaybhangale,

Could you check in Exercise 1 you are using the correct url (`url=request_url`). Hope that helps with `offset` not updating.

---

<div class="post-metadata">

**Author:** ![Georgios](https://avatars.discourse-cdn.com/v4/letter/g/eb9ed0/32.png) [@Georgios](https://community.deeplearning.ai/u/Georgios)\
**Post date:** [September 10, 2025, 12:49pm UTC](https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718/11 "2025-09-10T12:49:02Z")

</div>

Hello @vijaybhangale

Also please avoid sharing you code, could you remove it. Thank you

---

<div class="post-metadata">

**Author:** ![Deepa-183](https://avatars.discourse-cdn.com/v4/letter/d/df705f/32.png) [@Deepa-183](https://community.deeplearning.ai/u/Deepa-183)\
**Post date:** [September 10, 2025, 5:52pm UTC](https://community.deeplearning.ai/t/course-2-week-2-lab2-batch-data-processing-from-api/708718/12 "2025-09-10T17:52:34Z")

</div>

if “access\_token” in token\_response:  
headers = get\_auth\_header(  
access\_token=token\_response[“access\_token”]  
)  
print(“Token has been refreshed”)  
continue  
else:  
print(“Failed to refresh token.”)  
return

1. `if "access_token" in token_response:`

- This checks if the dictionary `token_response` contains the key `"access_token"`.

- If it does, that means the token refresh worked and you got a new token.

* * *

### 2. `headers = get_auth_header(access_token=token_response["access_token"])`

- Extracts the new access token: `token_response["access_token"]`.

- Calls `get_auth_header()` with that token.

- Stores the result in `headers`.  
(Most likely, this builds the HTTP headers with the refreshed token.)

* * *

### 3. `print("Token has been refreshed")`

- Just a confirmation message that the refresh worked.

* * *

### 4. `continue`

- Skips the rest of the loop and retries the request using the new token.

* * *

### 5. `else:`

- Runs if `"access_token"` is not found in `token_response`.

* * *

### 6. `print("Failed to refresh token.")`

- Prints an error message.

* * *

### 7. `return []`

- Exits the function and returns an empty list when the token couldn’t be refreshed.

-
