[GH-ISSUE #476] Exception: The following entries are missing in your headers: x-goog-authuser #353

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

Originally created by @ckujau on GitHub (Nov 22, 2023).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/476

Describe the bug
ytmusic-deleter (v1.5.6) fails because of a missing header x-goog-authuser, see the full error below.

To Reproduce
Steps to reproduce the behavior:

  1. Login to https://music.youtube.com/browse
  2. Copy the request header
  3. Start e.g. ytmusic-deleter delete-playlists and paste the request header:
$ ytmusic-deleter delete-playlists
[2023-11-22 17:42:29] Looking for headers_auth.json"
Failed loading provided credentials. Make sure to provide a string or a file path. Reason: the JSON object must be str, bytes or bytearray, not PosixPath
[2023-11-22 17:42:29] Creating headers_auth.json file...
Please paste the request headers from Firefox and press Ctrl-D to continue:
GET /browse HTTP/1.1
Host: music.youtube.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.7,de;q=0.3
Accept-Encoding: gzip, deflate, br
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
DNT: 1
Sec-GPC: 1
Connection: keep-alive
Cookie: SOCS=CAESNQgRE[...]
^D
Traceback (most recent call last):
  File "/home/christian/.local/lib/python3.12/site-packages/ytmusic_deleter/cli.py", line 23, in ensure_auth
    youtube_auth = YTMusic(headers_file_path)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/ytmusicapi/ytmusic.py", line 98, in __init__
    if 'x-goog-visitor-id' not in self.headers:
                                  ^^^^^^^^^^^^
AttributeError: 'YTMusic' object has no attribute 'headers'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/christian/.local/bin/ytmusic-deleter", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/click/core.py", line 1685, in invoke
    super().invoke(ctx)
  File "/home/christian/.local/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/ytmusic_deleter/cli.py", line 67, in cli
    ensure_auth(credential_dir)
  File "/home/christian/.local/lib/python3.12/site-packages/ytmusic_deleter/cli.py", line 27, in ensure_auth
    youtube_auth = YTMusic(YTMusic.setup(filepath=headers_file_path))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/ytmusicapi/ytmusic.py", line 170, in setup
    return setup(filepath, headers_raw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/ytmusicapi/setup.py", line 36, in setup
    raise Exception(
Exception: The following entries are missing in your headers: x-goog-authuser. Please try a different request (such as /browse) and make sure you are logged in.

Additional context
Indeed, the header x-goog-authuser is nowhere to be found. I tried to adjust the missing headers routine to match on some existing header, but failed to do so. However, removing that whole missing_headers function appears to do the trick and worked just fine:

$ ytmusic-deleter delete-playlists
[2023-11-22 17:51:37] Looking for headers_auth.json"
Failed loading provided credentials. Make sure to provide a string or a file path. Reason: the JSON object must be str, bytes or bytearray, not PosixPath
[2023-11-22 17:51:37] Creating headers_auth.json file...
Please paste the request headers from Firefox and press Ctrl-D to continue:
[...]
[2023-11-22 17:51:40] Created headers_auth.json"
[2023-11-22 17:51:40] Retrieving all your playlists...
[2023-11-22 17:51:40]   Retrieved 1 playlists.
[2023-11-22 17:51:40] Begin deleting playlists...
[2023-11-22 17:51:40] Processing playlist: Episodes for Later
[2023-11-22 17:51:40]   Could not delete playlist Episodes for Later. It might be a YT Music curated playlist.
[2023-11-22 17:51:40] Finished deleting all playlists

Playlists Deleted 100%|██████████| 1/1 [00:00<00:00, 14.59 playlists/s]

So, the diff would be:

$ diff -u ytmusicapi/setup.py{.orig,}
--- ytmusicapi/setup.py.orig    2023-11-22 17:48:16.603906780 +0100
+++ ytmusicapi/setup.py 2023-11-22 17:51:35.863463946 +0100
@@ -31,13 +31,6 @@
     except Exception as e:
         raise Exception("Error parsing your input, please try again. Full error: " + str(e))
 
-    missing_headers = {"cookie", "x-goog-authuser"} - set(k.lower() for k in user_headers.keys())
-    if missing_headers:
-        raise Exception(
-            "The following entries are missing in your headers: " + ", ".join(missing_headers)
-            + ". Please try a different request (such as /browse) and make sure you are logged in."
-        )
-
     ignore_headers = {"host", "content-length", "accept-encoding"}
     for i in ignore_headers:
         user_headers.pop(i, None)

Not creating a PR of course, for obvious reasons :)

Originally created by @ckujau on GitHub (Nov 22, 2023). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/476 **Describe the bug** `ytmusic-deleter` (v1.5.6) fails because of a missing header `x-goog-authuser`, see the full error below. **To Reproduce** Steps to reproduce the behavior: 1. Login to https://music.youtube.com/browse 2. Copy the request header 4. Start e.g. `ytmusic-deleter delete-playlists` and paste the request header: ``` $ ytmusic-deleter delete-playlists [2023-11-22 17:42:29] Looking for headers_auth.json" Failed loading provided credentials. Make sure to provide a string or a file path. Reason: the JSON object must be str, bytes or bytearray, not PosixPath [2023-11-22 17:42:29] Creating headers_auth.json file... Please paste the request headers from Firefox and press Ctrl-D to continue: GET /browse HTTP/1.1 Host: music.youtube.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Language: en-US,en;q=0.7,de;q=0.3 Accept-Encoding: gzip, deflate, br Upgrade-Insecure-Requests: 1 Sec-Fetch-Dest: document Sec-Fetch-Mode: navigate Sec-Fetch-Site: none Sec-Fetch-User: ?1 DNT: 1 Sec-GPC: 1 Connection: keep-alive Cookie: SOCS=CAESNQgRE[...] ^D Traceback (most recent call last): File "/home/christian/.local/lib/python3.12/site-packages/ytmusic_deleter/cli.py", line 23, in ensure_auth youtube_auth = YTMusic(headers_file_path) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/christian/.local/lib/python3.12/site-packages/ytmusicapi/ytmusic.py", line 98, in __init__ if 'x-goog-visitor-id' not in self.headers: ^^^^^^^^^^^^ AttributeError: 'YTMusic' object has no attribute 'headers' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/christian/.local/bin/ytmusic-deleter", line 8, in <module> sys.exit(cli()) ^^^^^ File "/home/christian/.local/lib/python3.12/site-packages/click/core.py", line 1157, in __call__ return self.main(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/christian/.local/lib/python3.12/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "/home/christian/.local/lib/python3.12/site-packages/click/core.py", line 1685, in invoke super().invoke(ctx) File "/home/christian/.local/lib/python3.12/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, **ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/christian/.local/lib/python3.12/site-packages/click/core.py", line 783, in invoke return __callback(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/christian/.local/lib/python3.12/site-packages/click/decorators.py", line 33, in new_func return f(get_current_context(), *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/christian/.local/lib/python3.12/site-packages/ytmusic_deleter/cli.py", line 67, in cli ensure_auth(credential_dir) File "/home/christian/.local/lib/python3.12/site-packages/ytmusic_deleter/cli.py", line 27, in ensure_auth youtube_auth = YTMusic(YTMusic.setup(filepath=headers_file_path)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/christian/.local/lib/python3.12/site-packages/ytmusicapi/ytmusic.py", line 170, in setup return setup(filepath, headers_raw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/christian/.local/lib/python3.12/site-packages/ytmusicapi/setup.py", line 36, in setup raise Exception( Exception: The following entries are missing in your headers: x-goog-authuser. Please try a different request (such as /browse) and make sure you are logged in. ``` **Additional context** Indeed, the header `x-goog-authuser` is nowhere to be found. I tried to adjust the missing headers routine to match on some existing header, but failed to do so. However, removing that whole `missing_headers` function appears to do the trick and worked just fine: ``` $ ytmusic-deleter delete-playlists [2023-11-22 17:51:37] Looking for headers_auth.json" Failed loading provided credentials. Make sure to provide a string or a file path. Reason: the JSON object must be str, bytes or bytearray, not PosixPath [2023-11-22 17:51:37] Creating headers_auth.json file... Please paste the request headers from Firefox and press Ctrl-D to continue: [...] [2023-11-22 17:51:40] Created headers_auth.json" [2023-11-22 17:51:40] Retrieving all your playlists... [2023-11-22 17:51:40] Retrieved 1 playlists. [2023-11-22 17:51:40] Begin deleting playlists... [2023-11-22 17:51:40] Processing playlist: Episodes for Later [2023-11-22 17:51:40] Could not delete playlist Episodes for Later. It might be a YT Music curated playlist. [2023-11-22 17:51:40] Finished deleting all playlists Playlists Deleted 100%|██████████| 1/1 [00:00<00:00, 14.59 playlists/s] ``` So, the diff would be: ``` $ diff -u ytmusicapi/setup.py{.orig,} --- ytmusicapi/setup.py.orig 2023-11-22 17:48:16.603906780 +0100 +++ ytmusicapi/setup.py 2023-11-22 17:51:35.863463946 +0100 @@ -31,13 +31,6 @@ except Exception as e: raise Exception("Error parsing your input, please try again. Full error: " + str(e)) - missing_headers = {"cookie", "x-goog-authuser"} - set(k.lower() for k in user_headers.keys()) - if missing_headers: - raise Exception( - "The following entries are missing in your headers: " + ", ".join(missing_headers) - + ". Please try a different request (such as /browse) and make sure you are logged in." - ) - ignore_headers = {"host", "content-length", "accept-encoding"} for i in ignore_headers: user_headers.pop(i, None) ``` Not creating a PR of course, for obvious reasons :)
kerem closed this issue 2026-02-27 23:00:20 +03:00
Author
Owner

@sigma67 commented on GitHub (Nov 22, 2023):

The project you're using is pinning a pretty old version of ytmusicapi (0.25). Can you try with latest and report back?

<!-- gh-comment-id:1823297464 --> @sigma67 commented on GitHub (Nov 22, 2023): The project you're using is pinning a pretty old version of ytmusicapi (0.25). Can you try with latest and report back?
Author
Owner

@ckujau commented on GitHub (Nov 22, 2023):

Oh, I didn't realize that! I used pip install ytmusic-deleter and it's really pinning this old version of ytmusicapi, wow. And now I realize that I've opened this issue to the wrong project, sorry about that.

FWIW, I've now installed both projects with the latest version

$ git clone https://github.com/apastel/ytmusic-deleter.git
$ cd ytmusic_deleter
=> Replace "ytmusicapi == 0.25.0" with just "ytmusicapi"

$ pip install git+https://github.com/sigma67/ytmusicapi .
$ pip list | grep ytmusic
ytmusic-deleter           1.5.6+9.gc0a0ecb.dirty
ytmusicapi                1.3.3.dev4+g38b4905

But the result is basically the same:

$ ytmusicapi browser
Creating browser.json with your authentication credentials...
Please paste the request headers from Firefox and press Ctrl-D to continue:
GET /browse HTTP/1.1
Host: music.youtube.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.7,de;q=0.3
Accept-Encoding: gzip, deflate, br
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1
DNT: 1
Sec-GPC: 1
Connection: keep-alive
Cookie: SOCS=CAESNQgREi[....]
Traceback (most recent call last):
  File "/home/christian/.local/bin/ytmusicapi", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/ytmusicapi/setup.py", line 62, in main
    return setup(filename)
           ^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/ytmusicapi/setup.py", line 22, in setup
    return setup_browser(filepath, headers_raw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/christian/.local/lib/python3.12/site-packages/ytmusicapi/auth/browser.py", line 52, in setup_browser
    raise Exception(
Exception: The following entries are missing in your headers: x-goog-authuser. Please try a different request (such as /browse) and make sure you are logged in.

Removing that missing_headers function again appears to "work" and a browser.json is then created.

$ diff -u auth/browser.py{.orig,}
--- auth/browser.py.orig        2023-11-22 21:22:33.733457479 +0100
+++ auth/browser.py     2023-11-22 21:22:57.266626640 +0100
@@ -47,13 +47,6 @@
     except Exception as e:
         raise Exception(f"Error parsing your input, please try again. Full error: {e}") from e
 
-    missing_headers = {"cookie", "x-goog-authuser"} - set(k.lower() for k in user_headers.keys())
-    if missing_headers:
-        raise Exception(
-            "The following entries are missing in your headers: " + ", ".join(missing_headers)
-            + ". Please try a different request (such as /browse) and make sure you are logged in."
-        )
-
     ignore_headers = {"host", "content-length", "accept-encoding"}
     for key in user_headers.copy().keys():
         if key.startswith("sec") or key in ignore_headers:

Unfortunately, ytmusic-deleter is then failing again, but with a different error. But that's material for an issue in the ytmusic-deleter project :-)

I was tempted to close this issue because I mixed up ytmusicapi with ytmusic-deleter but since ytmusicapi browser is showing the same error now, I'll leave it open.

<!-- gh-comment-id:1823465049 --> @ckujau commented on GitHub (Nov 22, 2023): Oh, I didn't realize that! I used `pip install ytmusic-deleter` and it's really [pinning](https://github.com/apastel/ytmusic-deleter/blob/master/setup.py#L17) this old version of `ytmusicapi`, wow. And now I realize that I've opened this issue to the wrong project, sorry about that. FWIW, I've now installed both projects with the latest version ``` $ git clone https://github.com/apastel/ytmusic-deleter.git $ cd ytmusic_deleter => Replace "ytmusicapi == 0.25.0" with just "ytmusicapi" $ pip install git+https://github.com/sigma67/ytmusicapi . $ pip list | grep ytmusic ytmusic-deleter 1.5.6+9.gc0a0ecb.dirty ytmusicapi 1.3.3.dev4+g38b4905 ``` But the result is basically the same: ``` $ ytmusicapi browser Creating browser.json with your authentication credentials... Please paste the request headers from Firefox and press Ctrl-D to continue: GET /browse HTTP/1.1 Host: music.youtube.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Language: en-US,en;q=0.7,de;q=0.3 Accept-Encoding: gzip, deflate, br Upgrade-Insecure-Requests: 1 Sec-Fetch-Dest: document Sec-Fetch-Mode: navigate Sec-Fetch-Site: none Sec-Fetch-User: ?1 DNT: 1 Sec-GPC: 1 Connection: keep-alive Cookie: SOCS=CAESNQgREi[....] Traceback (most recent call last): File "/home/christian/.local/bin/ytmusicapi", line 8, in <module> sys.exit(main()) ^^^^^^ File "/home/christian/.local/lib/python3.12/site-packages/ytmusicapi/setup.py", line 62, in main return setup(filename) ^^^^^^^^^^^^^^^ File "/home/christian/.local/lib/python3.12/site-packages/ytmusicapi/setup.py", line 22, in setup return setup_browser(filepath, headers_raw) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/christian/.local/lib/python3.12/site-packages/ytmusicapi/auth/browser.py", line 52, in setup_browser raise Exception( Exception: The following entries are missing in your headers: x-goog-authuser. Please try a different request (such as /browse) and make sure you are logged in. ``` Removing that `missing_headers` function again appears to "work" and a `browser.json` is then created. ``` $ diff -u auth/browser.py{.orig,} --- auth/browser.py.orig 2023-11-22 21:22:33.733457479 +0100 +++ auth/browser.py 2023-11-22 21:22:57.266626640 +0100 @@ -47,13 +47,6 @@ except Exception as e: raise Exception(f"Error parsing your input, please try again. Full error: {e}") from e - missing_headers = {"cookie", "x-goog-authuser"} - set(k.lower() for k in user_headers.keys()) - if missing_headers: - raise Exception( - "The following entries are missing in your headers: " + ", ".join(missing_headers) - + ". Please try a different request (such as /browse) and make sure you are logged in." - ) - ignore_headers = {"host", "content-length", "accept-encoding"} for key in user_headers.copy().keys(): if key.startswith("sec") or key in ignore_headers: ``` Unfortunately, [ytmusic-deleter](https://github.com/apastel/ytmusic-deleter) is then failing again, but with a different error. But that's material for an issue in the `ytmusic-deleter` project :-) I was tempted to close this issue because I mixed up `ytmusicapi` with `ytmusic-deleter` but since `ytmusicapi browser` is showing the same error now, I'll leave it open.
Author
Owner

@sigma67 commented on GitHub (Nov 22, 2023):

It's pretty strange that your paste does not contain any X-Headers. What method did you use to retrieve the headers?

On second look, I see the problem now. You're pasting a GET request, not a POST request.

Please read the instructions carefully: https://ytmusicapi.readthedocs.io/en/stable/setup/browser.html#copy-authentication-headers

<!-- gh-comment-id:1823531073 --> @sigma67 commented on GitHub (Nov 22, 2023): It's pretty strange that your paste does not contain any X-Headers. What method did you use to retrieve the headers? On second look, I see the problem now. You're pasting a GET request, not a POST request. Please read the instructions carefully: https://ytmusicapi.readthedocs.io/en/stable/setup/browser.html#copy-authentication-headers
Author
Owner

@ckujau commented on GitHub (Nov 23, 2023):

I could not find a POST request anywhere so I used the /browse request that happens to be GET. True, it's missing that particular header, but with the workaround above it works anyway, no x-goog-authuser required.

<!-- gh-comment-id:1823927405 --> @ckujau commented on GitHub (Nov 23, 2023): I could not find a `POST` request anywhere so I used the `/browse` request that happens to be `GET`. True, it's missing that particular header, but with the workaround above it works anyway, no `x-goog-authuser` required.
Author
Owner

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

I wouldn't guarantee that everything works as expected. You can create a POST request simply by navigating to the library for example while keeping the network tab open

<!-- gh-comment-id:1823978336 --> @sigma67 commented on GitHub (Nov 23, 2023): I wouldn't guarantee that everything works as expected. You can create a POST request simply by navigating to the library for example while keeping the network tab open
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#353
No description provided.