[GH-ISSUE #48] Redirect loop when running on Google App Engine with Task Queue #24

Closed
opened 2026-02-27 23:20:26 +03:00 by kerem · 1 comment
Owner

Originally created by @rknLA on GitHub (Apr 9, 2015).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/48

Hi Paul,

I'm not sure if this is a GAE problem, a requests problem, or something on Spotify's end, but I'm opening this here to make sure it's not the latter.

I have some python code that looks similar to the following:

import spotipy
Spotify = spotipy.Spotify()

def some_task_queue_handler(request):
    spotify_uri = get_spotify_uri_from_task_queue_request(request)
    metadata = Spotify.track(spotify_uri)
    logging.info("metadata is: %s", metadata)
    return None, 204

The issue that I'm running into is that both locally and when deployed, the spotipy requests are resulting in a redirect loop, where the location set by the redirect response is exactly the same every time. I've modified the requests session handler a little bit to print out the history that it collects when following redirects, and I get 30 items that look identical to this:

CaseInsensitiveDict({'content-length': '178', 'via': 'HTTP/1.1 GWA', 'x-google-cache-control': 'remote-fetch', 'server': 'nginx', 'connection': 'keep-alive', 'location': 'https://api.spotify.com/v1/tracks/2wNO69huzAY2WBnigjXMQ4', 'date': 'Thu, 09 Apr 2015 20:32:17 GMT', 'content-type': 'text/html'})

Is this bouncing happening on the Spotify end? Possibly due to some user agent or origin IP? Or Do I need to set an auth parameter to make the call from a GAE server?

When I run curl on the same URL from my local command line, I get a valid response:

rknLA:~() $ curl -v https://api.spotify.com/v1/tracks/2wNO69huzAY2WBnigjXMQ4                                                                                                                                                                          09.04.2015 [22:52:11]
* Hostname was NOT found in DNS cache
*   Trying 194.14.177.4...
* Connected to api.spotify.com (194.14.177.4) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
* Server certificate: *.spotify.com
* Server certificate: DigiCert SHA2 Secure Server CA
* Server certificate: DigiCert Global Root CA
> GET /v1/tracks/2wNO69huzAY2WBnigjXMQ4 HTTP/1.1
> User-Agent: curl/7.37.1
> Host: api.spotify.com
> Accept: */*
>
< HTTP/1.1 200 OK
* Server nginx is not blacklisted
< Server: nginx
< Date: Thu, 09 Apr 2015 20:52:19 GMT
< Content-Type: application/json; charset=utf-8
< Content-Length: 2488
< Connection: keep-alive
< Keep-Alive: timeout=600
< Vary: Accept-Encoding
< Cache-Control: public, max-age=7200
< Access-Control-Allow-Headers: Accept, Authorization, Origin, Content-Type
< Access-Control-Allow-Origin: *
< Access-Control-Max-Age: 604800
< Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE
< Access-Control-Allow-Credentials: true
< X-Content-Type-Options: nosniff
< Strict-Transport-Security: max-age=31536000;
<
{
  "album" : {
    "album_type" : "single",
    "available_markets" : [ "AD", "AR", "AT", "AU", "BE", "BG", "BO", "BR", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "EC", "EE", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HU", "IE", "IS", "IT", "LI", "LT", "LU", "LV", "MC", "MT", "MX", "MY", "NI", "NL", "NO", "NZ", "PA", "PE", "PH", "PL", "PT", "PY", "RO", "SE", "SG", "SI", "SK", "SV", "TR", "TW", "US", "UY" ],
    "external_urls" : {
      "spotify" : "https://open.spotify.com/album/70g5xd035UlaLDn1bFPHHM"
    },
    "href" : "https://api.spotify.com/v1/albums/70g5xd035UlaLDn1bFPHHM",
    "id" : "70g5xd035UlaLDn1bFPHHM",
    "images" : [ {
      "height" : 640,
      "url" : "https://i.scdn.co/image/54ef204750e0c36c9facfac3fd8148a2ed6fead8",
      "width" : 640
    }, {
      "height" : 300,
      "url" : "https://i.scdn.co/image/d60bde19570f4880fde094185cdb750271ebcda4",
      "width" : 300
    }, {
      "height" : 64,
      "url" : "https://i.scdn.co/image/ad556ebf704e4450ce6152c5f4e66cab0636b2de",
      "width" : 64
    } ],
    "name" : "Project Destati: Awakening",
    "type" : "album",
    "uri" : "spotify:album:70g5xd035UlaLDn1bFPHHM"
  },
  "artists" : [ {
    "external_urls" : {
      "spotify" : "https://open.spotify.com/artist/7q3OTml6VefMn69k5EOwnx"
    },
    "href" : "https://api.spotify.com/v1/artists/7q3OTml6VefMn69k5EOwnx",
    "id" : "7q3OTml6VefMn69k5EOwnx",
    "name" : "Project Destati",
    "type" : "artist",
    "uri" : "spotify:artist:7q3OTml6VefMn69k5EOwnx"
  } ],
  "available_markets" : [ "AD", "AR", "AT", "AU", "BE", "BG", "BO", "BR", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "EC", "EE", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HU", "IE", "IS", "IT", "LI", "LT", "LU", "LV", "MC", "MT", "MX", "MY", "NI", "NL", "NO", "NZ", "PA", "PE", "PH", "PL", "PT", "PY", "RO", "SE", "SG", "SI", "SK", "SV", "TR", "TW", "US", "UY" ],
  "disc_number" : 1,
  "duration_ms" : 311749,
  "explicit" : false,
  "external_ids" : {
    "isrc" : "USE830908262"
  },
  "external_urls" : {
    "spotify" : "https://open.spotify.com/track/2wNO69huzAY2WBnigjXMQ4"
  },
  "href" : "https://api.spotify.com/v1/tracks/2wNO69huzAY2WBnigjXMQ4",
  "id" : "2wNO69huzAY2WBnigjXMQ4",
  "name" : "Sinister Sunburn",
  "popularity" : 28,
  "preview_url" : "https://p.scdn.co/mp3-preview/87603ffc63bc0ba98c37145e07287fdf3d7baffc",
  "track_number" : 3,
  "type" : "track",
  "uri" : "spotify:track:2wNO69huzAY2WBnigjXMQ4"
* Connection #0 to host api.spotify.com left intact
}%

Thanks!

Originally created by @rknLA on GitHub (Apr 9, 2015). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/48 Hi Paul, I'm not sure if this is a GAE problem, a `requests` problem, or something on Spotify's end, but I'm opening this here to make sure it's not the latter. I have some python code that looks similar to the following: ``` import spotipy Spotify = spotipy.Spotify() def some_task_queue_handler(request): spotify_uri = get_spotify_uri_from_task_queue_request(request) metadata = Spotify.track(spotify_uri) logging.info("metadata is: %s", metadata) return None, 204 ``` The issue that I'm running into is that both locally and when deployed, the `spotipy` requests are resulting in a redirect loop, where the `location` set by the redirect response is exactly the same every time. I've modified the `requests` session handler a little bit to print out the `history` that it collects when following redirects, and I get 30 items that look identical to this: ``` CaseInsensitiveDict({'content-length': '178', 'via': 'HTTP/1.1 GWA', 'x-google-cache-control': 'remote-fetch', 'server': 'nginx', 'connection': 'keep-alive', 'location': 'https://api.spotify.com/v1/tracks/2wNO69huzAY2WBnigjXMQ4', 'date': 'Thu, 09 Apr 2015 20:32:17 GMT', 'content-type': 'text/html'}) ``` Is this bouncing happening on the Spotify end? Possibly due to some user agent or origin IP? Or Do I need to set an auth parameter to make the call from a GAE server? When I run `curl` on the same URL from my local command line, I get a valid response: ``` rknLA:~() $ curl -v https://api.spotify.com/v1/tracks/2wNO69huzAY2WBnigjXMQ4 09.04.2015 [22:52:11] * Hostname was NOT found in DNS cache * Trying 194.14.177.4... * Connected to api.spotify.com (194.14.177.4) port 443 (#0) * TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 * Server certificate: *.spotify.com * Server certificate: DigiCert SHA2 Secure Server CA * Server certificate: DigiCert Global Root CA > GET /v1/tracks/2wNO69huzAY2WBnigjXMQ4 HTTP/1.1 > User-Agent: curl/7.37.1 > Host: api.spotify.com > Accept: */* > < HTTP/1.1 200 OK * Server nginx is not blacklisted < Server: nginx < Date: Thu, 09 Apr 2015 20:52:19 GMT < Content-Type: application/json; charset=utf-8 < Content-Length: 2488 < Connection: keep-alive < Keep-Alive: timeout=600 < Vary: Accept-Encoding < Cache-Control: public, max-age=7200 < Access-Control-Allow-Headers: Accept, Authorization, Origin, Content-Type < Access-Control-Allow-Origin: * < Access-Control-Max-Age: 604800 < Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE < Access-Control-Allow-Credentials: true < X-Content-Type-Options: nosniff < Strict-Transport-Security: max-age=31536000; < { "album" : { "album_type" : "single", "available_markets" : [ "AD", "AR", "AT", "AU", "BE", "BG", "BO", "BR", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "EC", "EE", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HU", "IE", "IS", "IT", "LI", "LT", "LU", "LV", "MC", "MT", "MX", "MY", "NI", "NL", "NO", "NZ", "PA", "PE", "PH", "PL", "PT", "PY", "RO", "SE", "SG", "SI", "SK", "SV", "TR", "TW", "US", "UY" ], "external_urls" : { "spotify" : "https://open.spotify.com/album/70g5xd035UlaLDn1bFPHHM" }, "href" : "https://api.spotify.com/v1/albums/70g5xd035UlaLDn1bFPHHM", "id" : "70g5xd035UlaLDn1bFPHHM", "images" : [ { "height" : 640, "url" : "https://i.scdn.co/image/54ef204750e0c36c9facfac3fd8148a2ed6fead8", "width" : 640 }, { "height" : 300, "url" : "https://i.scdn.co/image/d60bde19570f4880fde094185cdb750271ebcda4", "width" : 300 }, { "height" : 64, "url" : "https://i.scdn.co/image/ad556ebf704e4450ce6152c5f4e66cab0636b2de", "width" : 64 } ], "name" : "Project Destati: Awakening", "type" : "album", "uri" : "spotify:album:70g5xd035UlaLDn1bFPHHM" }, "artists" : [ { "external_urls" : { "spotify" : "https://open.spotify.com/artist/7q3OTml6VefMn69k5EOwnx" }, "href" : "https://api.spotify.com/v1/artists/7q3OTml6VefMn69k5EOwnx", "id" : "7q3OTml6VefMn69k5EOwnx", "name" : "Project Destati", "type" : "artist", "uri" : "spotify:artist:7q3OTml6VefMn69k5EOwnx" } ], "available_markets" : [ "AD", "AR", "AT", "AU", "BE", "BG", "BO", "BR", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "EC", "EE", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HU", "IE", "IS", "IT", "LI", "LT", "LU", "LV", "MC", "MT", "MX", "MY", "NI", "NL", "NO", "NZ", "PA", "PE", "PH", "PL", "PT", "PY", "RO", "SE", "SG", "SI", "SK", "SV", "TR", "TW", "US", "UY" ], "disc_number" : 1, "duration_ms" : 311749, "explicit" : false, "external_ids" : { "isrc" : "USE830908262" }, "external_urls" : { "spotify" : "https://open.spotify.com/track/2wNO69huzAY2WBnigjXMQ4" }, "href" : "https://api.spotify.com/v1/tracks/2wNO69huzAY2WBnigjXMQ4", "id" : "2wNO69huzAY2WBnigjXMQ4", "name" : "Sinister Sunburn", "popularity" : 28, "preview_url" : "https://p.scdn.co/mp3-preview/87603ffc63bc0ba98c37145e07287fdf3d7baffc", "track_number" : 3, "type" : "track", "uri" : "spotify:track:2wNO69huzAY2WBnigjXMQ4" * Connection #0 to host api.spotify.com left intact }% ``` Thanks!
kerem closed this issue 2026-02-27 23:20:27 +03:00
Author
Owner

@rknLA commented on GitHub (Apr 9, 2015):

False alarm.

This is an issue with GAE+requests that's solved by forcing version 2.1.0, as mentioned in https://github.com/pythonforfacebook/facebook-sdk/issues/130

More info (and the source of the solution) on StackOverflow

<!-- gh-comment-id:91360258 --> @rknLA commented on GitHub (Apr 9, 2015): False alarm. This is an issue with GAE+requests that's solved by forcing version 2.1.0, as mentioned in https://github.com/pythonforfacebook/facebook-sdk/issues/130 More info (and the source of the solution) [on StackOverflow](http://stackoverflow.com/questions/21605328/python-requests-on-google-app-engine-not-working-for-https/21610822#21610822)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#24
No description provided.