[GH-ISSUE #380] Youtube API returning 401 #298

Closed
opened 2026-02-27 22:09:04 +03:00 by kerem · 2 comments
Owner

Originally created by @pickpj on GitHub (Apr 18, 2023).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/380

After setting up the youtube API my header looks like the following [token redacted]:

headers = {"access_token": "............", "expires_in": 62788, "refresh_token": "............", "scope": "https://www.googleapis.com/auth/youtube", "token_type": "Bearer"}
user_id = 

Then when running some command the following error is output

requests.exceptions.InvalidHeader: Header part (62788) from {'expires_in': 62788} must be of type str or bytes, not <class 'int'>

Putting the number in quotes fixes this error; however, a different error is output after searching youtube for the tracks

YouTube tracks: 40/47
Traceback (most recent call last):
  File "/home/lpl/.local/bin/spotify_to_ytmusic", line 8, in <module>
    sys.exit(main())
  File "/home/lpl/.local/lib/python3.10/site-packages/spotify_to_ytmusic/main.py", line 79, in main
    args.func(args)
  File "/home/lpl/.local/lib/python3.10/site-packages/spotify_to_ytmusic/controllers.py", line 54, in create
    playlistId = ytmusic.create_playlist(
  File "/home/lpl/.local/lib/python3.10/site-packages/spotify_to_ytmusic/ytmusic.py", line 19, in create_playlist
    return self.api.create_playlist(name, info, privacy, video_ids=tracks)
  File "/home/lpl/.local/lib/python3.10/site-packages/ytmusicapi/mixins/playlists.py", line 221, in create_playlist
    response = self._send_request(endpoint, body)
  File "/home/lpl/.local/lib/python3.10/site-packages/ytmusicapi/ytmusic.py", line 132, in _send_request
    raise Exception(message + error)
Exception: Server returned HTTP 401: Unauthorized.
You must be signed in to perform this operation.

I imagine it has to do with the access token, but I am unsure how to proceed.

P.S. The URL for setting up the youtube API has a comma appended at the end, which messes up the link.
Edit: Img of URL
urlcomma
Also forgot to mention I am using python 3.10.10

Originally created by @pickpj on GitHub (Apr 18, 2023). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/380 After setting up the youtube API my header looks like the following [token redacted]: ``` headers = {"access_token": "............", "expires_in": 62788, "refresh_token": "............", "scope": "https://www.googleapis.com/auth/youtube", "token_type": "Bearer"} user_id = ``` Then when running some command the following error is output ``` requests.exceptions.InvalidHeader: Header part (62788) from {'expires_in': 62788} must be of type str or bytes, not <class 'int'> ``` Putting the number in quotes fixes this error; however, a different error is output after searching youtube for the tracks ``` YouTube tracks: 40/47 Traceback (most recent call last): File "/home/lpl/.local/bin/spotify_to_ytmusic", line 8, in <module> sys.exit(main()) File "/home/lpl/.local/lib/python3.10/site-packages/spotify_to_ytmusic/main.py", line 79, in main args.func(args) File "/home/lpl/.local/lib/python3.10/site-packages/spotify_to_ytmusic/controllers.py", line 54, in create playlistId = ytmusic.create_playlist( File "/home/lpl/.local/lib/python3.10/site-packages/spotify_to_ytmusic/ytmusic.py", line 19, in create_playlist return self.api.create_playlist(name, info, privacy, video_ids=tracks) File "/home/lpl/.local/lib/python3.10/site-packages/ytmusicapi/mixins/playlists.py", line 221, in create_playlist response = self._send_request(endpoint, body) File "/home/lpl/.local/lib/python3.10/site-packages/ytmusicapi/ytmusic.py", line 132, in _send_request raise Exception(message + error) Exception: Server returned HTTP 401: Unauthorized. You must be signed in to perform this operation. ``` I imagine it has to do with the access token, but I am unsure how to proceed. P.S. The URL for setting up the youtube API has a comma appended at the end, which messes up the link. Edit: Img of URL ![urlcomma](https://user-images.githubusercontent.com/118209356/232905426-a7a06036-1dd6-4102-8519-ebe7ab982dfd.png) Also forgot to mention I am using python 3.10.10
kerem 2026-02-27 22:09:04 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@sigma67 commented on GitHub (Apr 18, 2023):

Are you sure you didn't add the comma by accident? I'll have to check about the integer bug.

<!-- gh-comment-id:1515111700 --> @sigma67 commented on GitHub (Apr 18, 2023): Are you sure you didn't add the comma by accident? I'll have to check about the integer bug.
Author
Owner

@sigma67 commented on GitHub (Apr 19, 2023):

Hi, please update ytmusicapi to 1.0.1 and try again :)

<!-- gh-comment-id:1515214157 --> @sigma67 commented on GitHub (Apr 19, 2023): Hi, please update `ytmusicapi` to 1.0.1 and try again :)
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#298
No description provided.