英文:
I cant add songs to my playlist at spotify
问题
I try to add a song to my playlist at Spotify. Here is my code:
import requests
import json
user_id = "user_id"
playlist_id = "playlist_id"
url = f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks"
headers = {
'Authorization': 'Bearer secret_auth_token',
'Content-Type': 'application/json',
}
payload = {
"uris": ["spotify:track:64PgpLHuQK3UJ5qZ875Vei"],
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.text)
Then I got this error:
requests.exceptions.InvalidSchema: No connection adapters were found for "https://api.spotify.com/v1/playlists/2oNkSJU1mGfTAg3ii9nLwc/tracks"
I have tested my auth token. It has necessary scopes. For example, I can create a playlist with this token. But I don't know why I can't add songs to my playlist when I try it with the code above. I am a new learner. If you can simplify the answer, that would help a lot.
英文:
I try to add a song to my playlist at spotify. Here is my code:
import requests
import json
user_id = "user_id"
playlist_id = "playlist_id"
url = f'"https://api.spotify.com/v1/playlists/{playlist_id}/tracks"'
headers = {
'Authorization': 'Bearer secret_auth_token',
'Content-Type': 'application/json',
}
payload = {
"uris": ["spotify:track:64PgpLHuQK3UJ5qZ875Vei"],
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.text)
Then I got this error:
requests.exceptions.InvalidSchema: No connection adapters were found for '"https://api.spotify.com/v1/playlists/2oNkSJU1mGfTAg3ii9nLwc/tracks"'
I have tested my auth token. It has necessary scopes. For example I can create playlist with this token. But I dont know why I can't add songs to my playlist when I try it with the code above. I am new learner if u can simplify the answer that would help a lot.
答案1
得分: 1
这是因为您在URL中使用了单引号和双引号的组合。尝试将其替换为以下内容,应该按预期工作:
url = f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks"
英文:
This is due to the combination of single and double quotes you are using in your URL. Try to replace it with this and it should work as expected:
url = f"https://api.spotify.com/v1/playlists/{playlist_id}/tracks"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论