[GH-ISSUE #183] Difficulty authenticating #139

Closed
opened 2026-02-27 22:08:15 +03:00 by kerem · 1 comment
Owner

Originally created by @wisdomtooth on GitHub (Mar 29, 2021).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/183

What am I doing wrong? I tried both the Firefox and the Chrome methods.

If I try authenticating via the python console, I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'headers_auth' is not defined

If I try it manually, I get:

Failed loading provided credentials. Make sure to provide a string or a file path. Reason: Invalid control character at: line 8 column 289 (char 565)
Traceback (most recent call last):
  File "remove_dupes.py", line 9, in <module>
    ytmusic = YTMusic('headers_auth.json')
  File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\site-packages\ytmusicapi\ytmusic.py", line 58, in __init__
    self.sapisid = sapisid_from_cookie(self.headers['Cookie'])
AttributeError: 'YTMusic' object has no attribute 'headers'

If I replace the LFs in the cookie with ; I get:

Traceback (most recent call last):
  File "remove_dupes.py", line 9, in <module>
    ytmusic = YTMusic('headers_auth.json')
  File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\site-packages\ytmusicapi\ytmusic.py", line 58, in __init__
    self.sapisid = sapisid_from_cookie(self.headers['Cookie'])
  File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\site-packages\ytmusicapi\helpers.py", line 39, in sapisid_from_cookie
    return cookie['SAPISID'].value
KeyError: 'SAPISID'
Originally created by @wisdomtooth on GitHub (Mar 29, 2021). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/183 What am I doing wrong? I tried both the Firefox and the Chrome methods. If I try authenticating via the python console, I get: ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'headers_auth' is not defined ``` If I try it manually, I get: ``` Failed loading provided credentials. Make sure to provide a string or a file path. Reason: Invalid control character at: line 8 column 289 (char 565) Traceback (most recent call last): File "remove_dupes.py", line 9, in <module> ytmusic = YTMusic('headers_auth.json') File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\site-packages\ytmusicapi\ytmusic.py", line 58, in __init__ self.sapisid = sapisid_from_cookie(self.headers['Cookie']) AttributeError: 'YTMusic' object has no attribute 'headers' ``` If I replace the LFs in the cookie with `;` I get: ``` Traceback (most recent call last): File "remove_dupes.py", line 9, in <module> ytmusic = YTMusic('headers_auth.json') File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\site-packages\ytmusicapi\ytmusic.py", line 58, in __init__ self.sapisid = sapisid_from_cookie(self.headers['Cookie']) File "C:\Users\andre\AppData\Local\Programs\Python\Python38-32\lib\site-packages\ytmusicapi\helpers.py", line 39, in sapisid_from_cookie return cookie['SAPISID'].value KeyError: 'SAPISID' ```
kerem closed this issue 2026-02-27 22:08:15 +03:00
Author
Owner

@wisdomtooth commented on GitHub (Mar 29, 2021):

Resolved adding quotes: YTMusic.setup(filepath="headers_auth.json")

<!-- gh-comment-id:809303082 --> @wisdomtooth commented on GitHub (Mar 29, 2021): Resolved adding quotes: `YTMusic.setup(filepath="headers_auth.json")`
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#139
No description provided.