[GH-ISSUE #409] Update Chrome authentication documentation #310

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

Originally created by @Onyenso on GitHub (Jul 14, 2023).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/409

I tried to create a new playlist using YTMusic.create_playlist() but it returns a 401 Unauthorized. Before this, I had already set up authentication using the setup() function. My authentication file has the right credentials as copied from my browser. When I call YTMusic.create_playlist(), I get the 401 error. Traceback:

Traceback (most recent call last):
  File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/Users/alphadev/Desktop/Switch Vibes/switch_vibes/views.py", line 62, in post
    new_yt_playlist = convert_spotify_to_yt(spotify_playist)
  File "/Users/alphadev/Desktop/Switch Vibes/switch_vibes/spotify_to_yt.py", line 144, in convert_spotify_to_yt
    yt_playlist = yt.create_playlist(
  File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/ytmusicapi/mixins/playlists.py", line 224, in create_playlist
    response = self._send_request(endpoint, body)
  File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/ytmusicapi/ytmusic.py", line 156, in _send_request
    raise Exception(message + error)
Exception: Server returned HTTP 401: Unauthorized.
You must be signed in to perform this operation.

Steps to reproduce the behavior:

  1. Create authentication file by calling the ytmusicapi.setup() method, passing in the right headers.
  2. Call YTMusic.create_playlist()

While trying to copy my request headers from my Chrome browser, I noticed that the usual structure of the text has changed from the last time I copied (a couple months ago.) So I just copied my cookie value and used it in my authentication file as described here. You might want to update the documentation at https://ytmusicapi.readthedocs.io/en/latest/setup/browser.html#copy-authentication-headers for Chrome browsers.

Originally created by @Onyenso on GitHub (Jul 14, 2023). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/409 I tried to create a new playlist using `YTMusic.create_playlist()` but it returns a 401 Unauthorized. Before this, I had already set up authentication using the `setup()` function. My authentication file has the right credentials as copied from my browser. When I call `YTMusic.create_playlist()`, I get the 401 error. Traceback: ``` Traceback (most recent call last): File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner response = get_response(request) File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view return view_func(*args, **kwargs) File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 70, in view return self.dispatch(request, *args, **kwargs) File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch response = self.handle_exception(exc) File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception self.raise_uncaught_exception(exc) File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception raise exc File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch response = handler(request, *args, **kwargs) File "/Users/alphadev/Desktop/Switch Vibes/switch_vibes/views.py", line 62, in post new_yt_playlist = convert_spotify_to_yt(spotify_playist) File "/Users/alphadev/Desktop/Switch Vibes/switch_vibes/spotify_to_yt.py", line 144, in convert_spotify_to_yt yt_playlist = yt.create_playlist( File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/ytmusicapi/mixins/playlists.py", line 224, in create_playlist response = self._send_request(endpoint, body) File "/Users/alphadev/Desktop/Switch Vibes/venv/lib/python3.10/site-packages/ytmusicapi/ytmusic.py", line 156, in _send_request raise Exception(message + error) Exception: Server returned HTTP 401: Unauthorized. You must be signed in to perform this operation. ``` Steps to reproduce the behavior: 1. Create authentication file by calling the `ytmusicapi.setup()` method, passing in the right headers. 2. Call `YTMusic.create_playlist()` While trying to copy my request headers from my Chrome browser, I noticed that the usual structure of the text has changed from the last time I copied (a couple months ago.) So I just copied my cookie value and used it in my authentication file as described [here](https://ytmusicapi.readthedocs.io/en/latest/setup/browser.html#manual-file-creation). You might want to update the documentation at https://ytmusicapi.readthedocs.io/en/latest/setup/browser.html#copy-authentication-headers for Chrome browsers.
kerem 2026-02-27 23:00:07 +03:00
Author
Owner

@sigma67 commented on GitHub (Jul 20, 2023):

Can you be more specific what is not working for you when creating the credentials from Chrome?

<!-- gh-comment-id:1643519080 --> @sigma67 commented on GitHub (Jul 20, 2023): Can you be more specific what is not working for you when creating the credentials from Chrome?
Author
Owner

@Onyenso commented on GitHub (Jul 20, 2023):

About the credentials on Chrome, the structure of the text has been changed. The screenshot shows what it looks like now. Also, what is the update on the 401 Unauthorized error? I'm sure I created my header file and passed it into setup(), but I kept getting the error when I try to create a palaylist.
Screenshot 2023-07-20 at 10 06 11

<!-- gh-comment-id:1643562665 --> @Onyenso commented on GitHub (Jul 20, 2023): About the credentials on Chrome, the structure of the text has been changed. The screenshot shows what it looks like now. Also, what is the update on the 401 Unauthorized error? I'm sure I created my header file and passed it into `setup()`, but I kept getting the error when I try to create a palaylist. <img width="591" alt="Screenshot 2023-07-20 at 10 06 11" src="https://github.com/sigma67/ytmusicapi/assets/63431050/d3bf198b-426e-49a7-8a4e-9954a64ae9a3">
Author
Owner

@Onyenso commented on GitHub (Jul 25, 2023):

I did a temporary fix. So the reason I was getting the 401 error was because the implementation for setup_browser in ytmusicapi.auth.browser no longer works for this new text format. Hence, it couldn't correctly parse the header text that is copied from Chrome. I did this instead and I was able to create a new header file. I don't know if this will work for the header text from other browsers:
Screenshot 2023-07-25 at 05 10 56

<!-- gh-comment-id:1649082513 --> @Onyenso commented on GitHub (Jul 25, 2023): I did a temporary fix. So the reason I was getting the 401 error was because the implementation for `setup_browser` in `ytmusicapi.auth.browser` no longer works for this new text format. Hence, it couldn't correctly parse the header text that is copied from Chrome. I did this instead and I was able to create a new header file. I don't know if this will work for the header text from other browsers: <img width="536" alt="Screenshot 2023-07-25 at 05 10 56" src="https://github.com/sigma67/ytmusicapi/assets/63431050/889162a8-c9ad-44b8-8bad-c8063647c837">
Author
Owner

@sigma67 commented on GitHub (Aug 4, 2023):

I mean the docs state the following:

and copy everything starting from “accept: */*” to the end of the section

I presume you copied some of the headers starting with the colon, that's why you got the error?

But I agree that we should probably raise an Exception in this case instead of letting the user run blindly into the 401.

<!-- gh-comment-id:1665315124 --> @sigma67 commented on GitHub (Aug 4, 2023): I mean the docs state the following: ``` and copy everything starting from “accept: */*” to the end of the section ``` I presume you copied some of the headers starting with the colon, that's why you got the error? But I agree that we should probably raise an Exception in this case instead of letting the user run blindly into the 401.
Author
Owner

@sigma67 commented on GitHub (Aug 4, 2023):

PR welcome.

<!-- gh-comment-id:1665318502 --> @sigma67 commented on GitHub (Aug 4, 2023): PR welcome.
Author
Owner

@sigma67 commented on GitHub (Aug 20, 2023):

I found the issue. For whatever reason, Chrome now copies key and value as separate lines.

<!-- gh-comment-id:1685322402 --> @sigma67 commented on GitHub (Aug 20, 2023): I found the issue. For whatever reason, Chrome now copies key and value as separate lines.
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#310
No description provided.