sigma67 / spotify_to_ytmusic

Clone a Spotify playlist to YouTube Music
MIT License
791 stars 65 forks source link

Requests from referer https://www.youtube.com are blocked #22

Closed Hish15 closed 2 years ago

Hish15 commented 2 years ago

After following every step of the Readme instructions, I get

Spotify tracks: 4/4
Traceback (most recent call last):
  File "C:\Users\phara\git\spotifyplaylist_to_ytmusic\YouTube.py", line 191, in <module>
    main()
  File "C:\Users\phara\git\spotifyplaylist_to_ytmusic\YouTube.py", line 182, in main
    videoIds = ytmusic.search_songs(playlist['tracks'])
  File "C:\Users\phara\git\spotifyplaylist_to_ytmusic\YouTube.py", line 70, in search_songs
    result = self.api.search(query, ignore_spelling=True)
  File "C:\Users\phara\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ytmusicapi\mixins\browsing.py", line 135, in search
    response = self._send_request(endpoint, body)
  File "C:\Users\phara\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\ytmusicapi\ytmusic.py", line 133, in _send_request
    raise Exception(message + error)
Exception: Server returned HTTP 403: Forbidden.
Requests from referer https://www.youtube.com are blocked

Is there something more to do to avoid the Forbidden error message?

sigma67 commented 2 years ago

Are you sure you followed the setup for ytmusicapi correctly? Step 5 in the instructions

2createTECH commented 2 years ago
Spotify tracks: 28/28
Traceback (most recent call last):
  File "YouTube.py", line 190, in <module>
    main()
  File "YouTube.py", line 182, in main
    videoIds = ytmusic.search_songs(playlist['tracks'])
  File "YouTube.py", line 70, in search_songs
    result = self.api.search(query)
  File "C:\Users\Pavel\AppData\Local\Programs\Python\Python36\lib\site-packages\ytmusicapi\mixins\browsing.py", line 141, in search
    response = self._send_request(endpoint, body)
  File "C:\Users\Pavel\AppData\Local\Programs\Python\Python36\lib\site-packages\ytmusicapi\ytmusic.py", line 142, in _send_request
    raise Exception(message + error)
Exception: Server returned HTTP 500: Internal Server Error.
Internal error encountered.

I followed the step 5 and attempted to get the headers from different browsers, but still get the error. Am I missing something else?

sigma67 commented 2 years ago

Your headers are almost certainly the issue. Try starting from scratch. I can try to debug for you if you send your headers to ytmusicapi@gmail.com

2createTECH commented 2 years ago

After further troubleshooting, I figured out why I was getting the Internal Server Error. In the settings.ini.example, I misunderstood the purpose of this line: user_id = I thought it was supposed to have my Google user_id, but that was not the case. The line needs to remain empty as specified in the example.

sigma67 commented 2 years ago

user_id is used for brand accounts, which you can create under your main account. If you don't have one, it's fine to leave it empty. So that means everything is working for you?

2createTECH commented 2 years ago

That's helpful to know. Yes, after leaving the user_id blank, everything started to work fine. I was following Find your YouTube user & channel IDs guide to identify the user_id value, however after entering the corresponding user id, I was getting that 500 error.

sigma67 commented 2 years ago

No, that's not related. See here for the correct procedure for brand accounts: https://ytmusicapi.readthedocs.io/en/latest/usage.html

But doesn't matter for you since you're not using a brand account.