mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-26 16:15:51 +03:00
[GH-ISSUE #774] Getting invalid context URI when passing variable containing URI to param for start_playback() #474
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#474
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @StanleyDharan on GitHub (Jan 24, 2022).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/774
I am reading the ID part of the spotify album URI from an external source and concatenating it to a base URI, doing this will cause an
invalid context uri, reason: noneerrorexample:
but if I hard code the variable
albumURIlike this:albumURI = 'spotify:album:6QC8G4HVk9lkbpxugU7ZgF'it will work... (to be exact, I could doprint(albumURI)copy the output and hard codealbumURIwith it and the function will execute)Im really confused why this happening,
datais a UFT-8 byteArray. I am also fairly new to python so if I am missing some string clean-up or something when decoding please let me know.This is the exact error I am getting:
*** = my actual device ID
Any guidance would be greatly appreciated.
@Peter-Schorn commented on GitHub (Jan 24, 2022):
There is no such thing as a "base URI". Post the value of
data.@StanleyDharan commented on GitHub (Jan 24, 2022):
dataa byteArray, its 16 bytes long, Idecode()it into a string and concatenate it toalbumURI = 'spotify:album:'at max there will be 3 16 byte long byteArrays that are
decode()and concatenated toalbumURI@Peter-Schorn commented on GitHub (Jan 24, 2022):
How could anyone solve your issue if you don't post the value of
data? If it contains a utf-8 encoded album id, then the code will work; if not, then you will get a "Invalid context uri" error.@StanleyDharan commented on GitHub (Jan 24, 2022):
Sorry, this is the content of data for the example I mentioned above;
The reason
datais printed 3 times is because I am looping through anarrayofByteArrays@Peter-Schorn commented on GitHub (Jan 24, 2022):
If you decode these
datavalues into strings and print them (why didn't you think of doing this?), it should be obvious why your code doesn't work:output:
\x00denotes the null character, which obviously shouldn't be present in a Spotify Id. Spotify Ids will always be alphanumeric characters. In fact, most of the characters in your byte arrays are non-printing control characters.@StanleyDharan commented on GitHub (Jan 24, 2022):
Thanks for all your help Peter! I solved the issue you laid out with this little filter function:
@Peter-Schorn commented on GitHub (Jan 24, 2022):
This is not sufficient because if you remove non-alphanumeric characters, then the string is not long enough to be a Spotify id, at least for the data objects you posted.
@StanleyDharan commented on GitHub (Jan 24, 2022):
So the data object after all the manipulation is done is appended to this string:
albumURI = 'spotify:album:'ie.
and that is then sent to
sp.start_playback(device_id='***', context_uri=albumURI)and its been working great :)@Peter-Schorn commented on GitHub (Jan 24, 2022):
But
gU7ZgFis not a valid Spotify id, and your last byte array (bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f')) doesn't contain any alphanumeric characters.@StanleyDharan commented on GitHub (Jan 24, 2022):
Oh sorry let me clarify with the full back story of what I am doing.
Short answer:
In your above comment where you listed out data1-3, those 3 data# variables are read, stripped and concatenated together with
albumURILong answer:
The reason i'm going through this process is because of a hardware limitation; I am reading the album ID from an mifare nfc card. The limitation is that; MiFare classic NFC cards have a limited # of data blocks to hold whatever data you want, each data block can contain 16 bytes, and must always contain 16 bytes of data. So because the album ID is longer then 16 I break it up over multiple data blocks BUT since the album ID isn't always long enough to fill 2 whole data blocks, I add in filler bytes
Im making this (watch the tiktok) https://www.tiktok.com/@talaexe/video/7051357248739659013?lang=en&is_copy_url=0&is_from_webapp=v1&sender_device=pc&sender_web_id=6925974970854508038