<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Spotify is randomly timing out my API requests? in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Spotify-is-randomly-timing-out-my-API-requests/m-p/5864304#M12564</link>
    <description>&lt;P&gt;401 means that the access token is expired. This happens after an hour.&lt;/P&gt;</description>
    <pubDate>Sun, 04 Feb 2024 14:07:46 GMT</pubDate>
    <dc:creator>Ximzend</dc:creator>
    <dc:date>2024-02-04T14:07:46Z</dc:date>
    <item>
      <title>Spotify is randomly timing out my API requests?</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Spotify-is-randomly-timing-out-my-API-requests/m-p/5863560#M12561</link>
      <description>&lt;P&gt;I have made an app in python that needs to update a UI with currently playing song info around every second (I have a progress bar for the songs duration) but my requests are randomly timed out with spotify returning a 401. I use spotipy to interact with the API and I have added my account to my dashboard, but no dice. Any suggestions would be appreciated. I have attached the error and here is my code that requests the API:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;username = &lt;SPAN&gt;'apple11533334334343'&lt;BR /&gt;&lt;/SPAN&gt;scope = &lt;SPAN&gt;'user-read-currently-playing'&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;token = util.prompt_for_user_token(username&lt;SPAN&gt;, &lt;/SPAN&gt;scope&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;redirect_uri&lt;/SPAN&gt;=&lt;SPAN&gt;'http://localhost:8888/callback'&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;spotify = spotipy.Spotify(&lt;SPAN&gt;auth&lt;/SPAN&gt;=token&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;requests_timeout&lt;/SPAN&gt;=&lt;SPAN&gt;10&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;retries&lt;/SPAN&gt;=&lt;SPAN&gt;10&lt;/SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;image_data = requests.get(&lt;SPAN&gt;'https://i.scdn.co/image/ab67616d000048515f1590fb5d2f9e1bed8bb2e8'&lt;/SPAN&gt;).content &lt;SPAN&gt;#creates a default image to be changed since get_info doesnt update fast enough&lt;BR /&gt;&lt;/SPAN&gt;track_name = &lt;SPAN&gt;str&lt;/SPAN&gt;()&lt;BR /&gt;artists_name = &lt;SPAN&gt;str&lt;/SPAN&gt;()&lt;BR /&gt;album_name = &lt;SPAN&gt;str&lt;/SPAN&gt;()&lt;BR /&gt;progress = &lt;SPAN&gt;0.1&lt;BR /&gt;&lt;/SPAN&gt;total_length = &lt;SPAN&gt;0.1&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;get_info&lt;/SPAN&gt;():&lt;BR /&gt;&lt;BR /&gt;    &lt;SPAN&gt;while True&lt;/SPAN&gt;:&lt;BR /&gt;&lt;BR /&gt;        &lt;SPAN&gt;try&lt;/SPAN&gt;:&lt;BR /&gt;&lt;BR /&gt;            &lt;SPAN&gt;info &lt;/SPAN&gt;= spotify.current_user_playing_track()&lt;BR /&gt;            &lt;BR /&gt;            &lt;SPAN&gt;#print(json.dumps(info, indent=4))&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;            &lt;SPAN&gt;global &lt;/SPAN&gt;image_data&lt;BR /&gt;            &lt;SPAN&gt;global &lt;/SPAN&gt;track_name&lt;BR /&gt;            &lt;SPAN&gt;global &lt;/SPAN&gt;artists_name&lt;BR /&gt;            &lt;SPAN&gt;global &lt;/SPAN&gt;album_name&lt;BR /&gt;            &lt;SPAN&gt;global &lt;/SPAN&gt;progress&lt;BR /&gt;            &lt;SPAN&gt;global &lt;/SPAN&gt;total_length&lt;BR /&gt;            &lt;BR /&gt;            &lt;SPAN&gt;#get the data from the json returned&lt;BR /&gt;&lt;/SPAN&gt;            track_name = &lt;SPAN&gt;info&lt;/SPAN&gt;[&lt;SPAN&gt;'item'&lt;/SPAN&gt;][&lt;SPAN&gt;'name'&lt;/SPAN&gt;]&lt;BR /&gt;            &lt;SPAN&gt;artists &lt;/SPAN&gt;= [&lt;SPAN&gt;artist &lt;/SPAN&gt;&lt;SPAN&gt;for &lt;/SPAN&gt;artist &lt;SPAN&gt;in &lt;/SPAN&gt;&lt;SPAN&gt;info&lt;/SPAN&gt;[&lt;SPAN&gt;'item'&lt;/SPAN&gt;][&lt;SPAN&gt;'artists'&lt;/SPAN&gt;]]&lt;BR /&gt;            artists_name = &lt;SPAN&gt;', '&lt;/SPAN&gt;.join([&lt;SPAN&gt;artist&lt;/SPAN&gt;[&lt;SPAN&gt;'name'&lt;/SPAN&gt;] &lt;SPAN&gt;for &lt;/SPAN&gt;artist &lt;SPAN&gt;in &lt;/SPAN&gt;&lt;SPAN&gt;artists&lt;/SPAN&gt;])&lt;BR /&gt;            &lt;SPAN&gt;image_info &lt;/SPAN&gt;= &lt;SPAN&gt;info&lt;/SPAN&gt;[&lt;SPAN&gt;'item'&lt;/SPAN&gt;][&lt;SPAN&gt;'album'&lt;/SPAN&gt;][&lt;SPAN&gt;'images'&lt;/SPAN&gt;][&lt;SPAN&gt;1&lt;/SPAN&gt;]&lt;BR /&gt;            album_name = &lt;SPAN&gt;info&lt;/SPAN&gt;[&lt;SPAN&gt;'item'&lt;/SPAN&gt;][&lt;SPAN&gt;'album'&lt;/SPAN&gt;][&lt;SPAN&gt;'name'&lt;/SPAN&gt;]&lt;BR /&gt;            &lt;SPAN&gt;progress_ms &lt;/SPAN&gt;= &lt;SPAN&gt;info&lt;/SPAN&gt;[&lt;SPAN&gt;'progress_ms'&lt;/SPAN&gt;]&lt;BR /&gt;            &lt;SPAN&gt;track_length &lt;/SPAN&gt;= &lt;SPAN&gt;info&lt;/SPAN&gt;[&lt;SPAN&gt;'item'&lt;/SPAN&gt;][&lt;SPAN&gt;'duration_ms'&lt;/SPAN&gt;]&lt;BR /&gt;            &lt;SPAN&gt;track_url &lt;/SPAN&gt;= &lt;SPAN&gt;info&lt;/SPAN&gt;[&lt;SPAN&gt;'item'&lt;/SPAN&gt;][&lt;SPAN&gt;'external_urls'&lt;/SPAN&gt;][&lt;SPAN&gt;'spotify'&lt;/SPAN&gt;]&lt;BR /&gt;            &lt;BR /&gt;            &lt;SPAN&gt;#make variables to use in app&lt;BR /&gt;&lt;/SPAN&gt;            track_name = &lt;SPAN&gt;'Song Title: ' &lt;/SPAN&gt;+ track_name&lt;BR /&gt;            artists_name = &lt;SPAN&gt;'Artists: ' &lt;/SPAN&gt;+ artists_name&lt;BR /&gt;            album_name = &lt;SPAN&gt;'Album Name: ' &lt;/SPAN&gt;+ album_name&lt;BR /&gt;            &lt;BR /&gt;            &lt;SPAN&gt;#convert the time to s for progress bar&lt;BR /&gt;&lt;/SPAN&gt;            progress = &lt;SPAN&gt;progress_ms &lt;/SPAN&gt;/ &lt;SPAN&gt;1000&lt;BR /&gt;&lt;/SPAN&gt;            total_length = &lt;SPAN&gt;track_length &lt;/SPAN&gt;/ &lt;SPAN&gt;1000&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;            &lt;BR /&gt;&lt;/SPAN&gt;            &lt;SPAN&gt;#get the image from the url to put in app&lt;BR /&gt;&lt;/SPAN&gt;            &lt;SPAN&gt;image_url &lt;/SPAN&gt;= &lt;SPAN&gt;image_info&lt;/SPAN&gt;[&lt;SPAN&gt;'url'&lt;/SPAN&gt;]&lt;BR /&gt;            image_data = requests.get(&lt;SPAN&gt;image_url&lt;/SPAN&gt;).content&lt;BR /&gt;&lt;BR /&gt;        &lt;SPAN&gt;except &lt;/SPAN&gt;&lt;SPAN&gt;TypeError&lt;/SPAN&gt;:&lt;BR /&gt;            track_name = &lt;SPAN&gt;'No Song Playing'&lt;BR /&gt;&lt;/SPAN&gt;            artists_name = &lt;SPAN&gt;'...'&lt;BR /&gt;&lt;/SPAN&gt;            album_name = &lt;SPAN&gt;'...'&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;except &lt;/SPAN&gt;socket.gaierror:&lt;BR /&gt;            &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;'Connection Error, try connecting wifi dumbass'&lt;/SPAN&gt;)&lt;BR /&gt;        &lt;SPAN&gt;except &lt;/SPAN&gt;&lt;SPAN&gt;ConnectionError &lt;/SPAN&gt;&lt;SPAN&gt;as &lt;/SPAN&gt;e:&lt;BR /&gt;            &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;f"Connection error encountered &lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;e&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;)&lt;BR /&gt;        &lt;SPAN&gt;except &lt;/SPAN&gt;&lt;SPAN&gt;TimeoutError&lt;/SPAN&gt;:&lt;BR /&gt;            &lt;SPAN&gt;print&lt;/SPAN&gt;(&lt;SPAN&gt;"Timeout Error"&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 04 Feb 2024 02:39:05 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Spotify-is-randomly-timing-out-my-API-requests/m-p/5863560#M12561</guid>
      <dc:creator>DylenLiverman</dc:creator>
      <dc:date>2024-02-04T02:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Spotify is randomly timing out my API requests?</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Spotify-is-randomly-timing-out-my-API-requests/m-p/5864304#M12564</link>
      <description>&lt;P&gt;401 means that the access token is expired. This happens after an hour.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2024 14:07:46 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Spotify-is-randomly-timing-out-my-API-requests/m-p/5864304#M12564</guid>
      <dc:creator>Ximzend</dc:creator>
      <dc:date>2024-02-04T14:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: Spotify is randomly timing out my API requests?</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Spotify-is-randomly-timing-out-my-API-requests/m-p/5864400#M12565</link>
      <description>&lt;P&gt;An hour of cumulative use? Because it happens at random times after I start making new requests. For example I have had times where I start the program and 30 seconds later I get 401, and then other times it takes like 30 minutes.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2024 15:01:54 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Spotify-is-randomly-timing-out-my-API-requests/m-p/5864400#M12565</guid>
      <dc:creator>DylenLiverman</dc:creator>
      <dc:date>2024-02-04T15:01:54Z</dc:date>
    </item>
  </channel>
</rss>

