spotify-web-api-kotlin icon indicating copy to clipboard operation
spotify-web-api-kotlin copied to clipboard

getAlbumTracks 400 Error when called often

Open michaeldomanek opened this issue 2 years ago • 7 comments

Describe the bug when I call api.albums.getAlbumTracks() for a lot of albums (e.g. 40 or 80), I get Received Status Code 400. Error cause: malformed request sent for some requests

To Reproduce

val api = spotifyAppApi()
val tracks = albumIds.flatMap { albumId ->
    api.albums.getAlbumTracks(albumId).getAllItemsNotNull()
}

create albumIds list from this file: albumIds.txt

Desktop:

  • OS: Windows
  • Kotlin/JVM
  • Project with Java 17
  • Kotlin 1.6

michaeldomanek avatar Apr 11 '22 22:04 michaeldomanek

Does this occur for the same ids every time?

adamint avatar Apr 11 '22 22:04 adamint

no every time other ids and sometimes it doesn't happen and sometimes e.g 5 request fail (avg. 2-6 requests fail)

michaeldomanek avatar Apr 11 '22 23:04 michaeldomanek

I have not reproduced this bug.

adamint avatar Apr 13 '22 06:04 adamint

Apologies, that was a typo. I have not been able to reproduce this bug on kotlin 1.6.20, version 3.8.6 @michaeldomanek after several thousands of requests. My code:

suspend fun main() = runBlocking {
    val api = spotifyAppApi("", "").build()
    api.spotifyApiOptions.enableDebugMode = true
    api.spotifyApiOptions.useCache = false

    val albumIds = File("${System.getProperty("user.home")}/Downloads/albumIds.txt").readText()
        .replace("[\\[\\]]".toRegex(), "")
        .split(", ")

    while (true) {
        val tracks = albumIds.map { albumId ->
            async {
                api.albums.getAlbumTracks(albumId).getAllItemsNotNull()
            }
        }.awaitAll()

        println(tracks)
    }

}

Can you give me more information around this behavior? Is there a particular exception or stacktrace you can share

adamint avatar Apr 15 '22 04:04 adamint

Hello @adamint thanks for looking into it. This is my Stacktrace: Stacktrace.txt I edited my comment because yesterday I thought it was a Java 17 problem and changing sdk solved the problem, but today it happened with other Java versions too.

michaeldomanek avatar Apr 16 '22 13:04 michaeldomanek

I created a new sample project to test it: kotlin-gradle-example The Stacktrace is from here if you want to look at it.

michaeldomanek avatar Apr 16 '22 22:04 michaeldomanek

Hi @michaeldomanek, I'm still unable to reproduce this with the given sample, on various JDKs (8, 11, 17). You reproduced it in this sample project? Do you have the debug console logs listing the request (from enableDebugMode)

adamint avatar Apr 19 '22 05:04 adamint

No additional info was provided, closing

adamint avatar Sep 19 '22 06:09 adamint