[GH-ISSUE #450] 'setvideoid' error on .get_history() #334

Closed
opened 2026-02-27 23:00:15 +03:00 by kerem · 6 comments
Owner

Originally created by @AsukoRin on GitHub (Oct 6, 2023).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/450

ytmusic = ytmusicapi.YTMusic(os.environ["browserjson"]) history = ytmusic.get_history() last_listened_song = history[0] if history else {}

history = ytmusic.get_history() gives a KeyError: 'setVideoId' even though it isn't editing or moving playlist items. A couple days ago the code worked normally with no errors and now it doesn't. I have tried to refresh the browser.json file (firefox) and object is created correctly:
<ytmusicapi.ytmusic.YTMusic object at 0x7fd50a96ea10>
However code still gives a key error, occasionally changing to Error: 'none'

Larger Snippet:
def get_last_listened_song(): global last_listened_song while True: try: history = ytmusic.get_history() print(history) last_listened_song = history[0] if history else {} print('done') time.sleep(5) except Exception as e: print("Error:", str(e))

My first time writing a bug report so sorry if I did something wrong :p

Originally created by @AsukoRin on GitHub (Oct 6, 2023). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/450 `ytmusic = ytmusicapi.YTMusic(os.environ["browserjson"]) history = ytmusic.get_history() last_listened_song = history[0] if history else {}` history = ytmusic.get_history() gives a KeyError: 'setVideoId' even though it isn't editing or moving playlist items. A couple days ago the code worked normally with no errors and now it doesn't. I have tried to refresh the browser.json file (firefox) and object is created correctly: `<ytmusicapi.ytmusic.YTMusic object at 0x7fd50a96ea10>` However code still gives a key error, occasionally changing to Error: 'none' Larger Snippet: `def get_last_listened_song(): global last_listened_song while True: try: history = ytmusic.get_history() print(history) last_listened_song = history[0] if history else {} print('done') time.sleep(5) except Exception as e: print("Error:", str(e))` My first time writing a bug report so sorry if I did something wrong :p
kerem 2026-02-27 23:00:15 +03:00
  • closed this issue
  • added the
    yt-update
    label
Author
Owner

@sigma67 commented on GitHub (Oct 6, 2023):

Please follow the standard issue bug template. Have you noticed any unusual changes in the web UI of your history?

music.youtube.com/history

<!-- gh-comment-id:1751087667 --> @sigma67 commented on GitHub (Oct 6, 2023): Please follow the standard issue bug template. Have you noticed any unusual changes in the web UI of your history? music.youtube.com/history
Author
Owner

@AsukoRin commented on GitHub (Oct 6, 2023):

It seems about the same, but there might have been some small change that I haven't noticed. I am still signed in as well

<!-- gh-comment-id:1751308683 --> @AsukoRin commented on GitHub (Oct 6, 2023): It seems about the same, but there might have been some small change that I haven't noticed. I am still signed in as well
Author
Owner

@joulev commented on GitHub (Oct 9, 2023):

Same here too, the following stopped working with the exact same error

import os
import json
from http.server import BaseHTTPRequestHandler
from ytmusicapi import YTMusic, setup

auth = setup(headers_raw=os.environ['YTMUSIC_HEADERS_RAW'])
ytmusic = YTMusic(auth)


class handler(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', 'application/json')
        self.end_headers()
        first_history = ytmusic.get_history()[0]
        message = {
            'videoId': first_history['videoId'],
            'title': first_history['title'],
            'artists': first_history['artists']
        }
        self.wfile.write(json.dumps(message).encode())
        return
File "./api/ytmusic.py", line 15, in do_GET
first_history = ytmusic.get_history()[0]
File "/var/task/ytmusicapi/mixins/library.py", line 216, in get_history
songlist = parse_playlist_items(data, menu_entries)
File "/var/task/ytmusicapi/parsers/playlists.py", line 23, in parse_playlist_items
setVideoId = menu_service['playlistEditEndpoint']['actions'][0][
KeyError: 'setVideoId'

Web UI of YouTube Music history page looks the same.

<!-- gh-comment-id:1752378339 --> @joulev commented on GitHub (Oct 9, 2023): Same here too, the following stopped working with the exact same error ```py import os import json from http.server import BaseHTTPRequestHandler from ytmusicapi import YTMusic, setup auth = setup(headers_raw=os.environ['YTMUSIC_HEADERS_RAW']) ytmusic = YTMusic(auth) class handler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.send_header('Content-type', 'application/json') self.end_headers() first_history = ytmusic.get_history()[0] message = { 'videoId': first_history['videoId'], 'title': first_history['title'], 'artists': first_history['artists'] } self.wfile.write(json.dumps(message).encode()) return ``` ``` File "./api/ytmusic.py", line 15, in do_GET first_history = ytmusic.get_history()[0] File "/var/task/ytmusicapi/mixins/library.py", line 216, in get_history songlist = parse_playlist_items(data, menu_entries) File "/var/task/ytmusicapi/parsers/playlists.py", line 23, in parse_playlist_items setVideoId = menu_service['playlistEditEndpoint']['actions'][0][ KeyError: 'setVideoId' ``` Web UI of YouTube Music history page looks the same.
Author
Owner

@joulev commented on GitHub (Oct 12, 2023):

Without any changes to the code, it suddenly works again at least from today.

<!-- gh-comment-id:1758838865 --> @joulev commented on GitHub (Oct 12, 2023): Without any changes to the code, it suddenly works again at least from today.
Author
Owner

@AsukoRin commented on GitHub (Oct 13, 2023):

Still having the same issue

<!-- gh-comment-id:1760654462 --> @AsukoRin commented on GitHub (Oct 13, 2023): Still having the same issue
Author
Owner

@sigma67 commented on GitHub (Oct 23, 2023):

closing this in favor of #462

<!-- gh-comment-id:1774641896 --> @sigma67 commented on GitHub (Oct 23, 2023): closing this in favor of #462
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/ytmusicapi#334
No description provided.